SP2276 RECTNG2 - Partitions

Description

A partition of a rectangle is either a whole rectangle or a subdivision the rectangle into either a upper part and a lower part or a left part and a right part, and each part is a partition of the corresponding rectangle. Figure 1 shows several examples of partitions. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP2276/3ca3fb12df53f6c6f892c24b40357d7c0e82940a.png) Figure 2 shows three equal sized rectangles, partitioned into sub-rectangles. Partition B is obtained from partition A by partitioning two of the sub-rectangles of A. Generally, if a partition B is obtained from A by partitioning one or more of its sub-rectangles, we say that B is finer than A, or that A is coarser than B. This relation is partial: partition C is neither coarser nor finer than A or B. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP2276/cf2e1775dbeb24974ce24df38bad2564d460fb38.png) Given two partitions D and E of the same rectangle, infinitely many partitions exist that are finer than both D and E. In Figure 3 both F and G are finer than D and E. Among the partitions that are finer than both D and E, a unique one exists that is coarsest. This partition is called the infimum of D and E. In Figure 3, partition F is the infimum of D and E. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP2276/50c795d25871708204a480a008c4de3b9cd0dd7d.png) In Figure 4, both H and J are coarser than D and E. Here J is the finest partition that is coarser than D and E. Then J is the supremum of D and E. ![](https://cdn.luogu.com.cn/upload/vjudge_pic/SP2276/79c03d020f685dd0365e1a8433ccbce9e77b3c9a.png) Write a program that, given two partitions of the same rectangle, finds the infimum and the supremum of these partitions.

Input Format

The input file contains one or more test cases. The first line of each test case gives the width w and height h of the rectangle (0 < w, h

Output Format

For every case in the input file the output contains a single line containing the case number (in the format shown in the sample), followed by the infimum and the supremum of the two partitions, using the same format as the input. Place a blank line after the output of each test case.