Description
A group of researchers are designing an experiment to test the IQ of a monkey. They will hang a banana atthe roof of a building, andatthe mean time, provide the monkey withsome blocks. If the monkey is clever enough, it shall be able to reach the banana by placing one block onthe top another to build a tower and climb up togetits favorite food.
The researchers have n types of blocks, and an unlimited supply of blocks of each type. Each type-i block was a rectangular solid with linear dimensions (xi, yi, zi). A block could be reoriented so that any two ofits three dimensions determined the dimensions ofthe base andthe other dimension was the height.
They want to make sure thatthe tallest tower possible by stacking blocks can reach the roof. The problem isthat, in building a tower, one block could only be placed on top of another block as long asthe two base dimensions ofthe upper block were both strictly smaller than the corresponding base dimensions ofthe lower block because there has to be somespaceforthe monkey to step on. This meant, for example, that blocks oriented to have equal-sized bases couldn't be stacked.
Your job istowrite a program that determines the height ofthe tallest tower the monkey can build with a givensetof blocks.
Input
The input file will contain one or more test cases. The first line of each test case contains an integer n,
representing thenumberof different blocks inthe following data set. The maximum value for n is30.
Each ofthe next n lines contains three integers representing the values xi, yi and zi.
Input is terminated by a value of zero (0) for n.
Output
For each test case, print one line containing the case number (they are numbered sequentially starting from1) andthe height ofthe tallest possible tower inthe format "Case case: maximum height = height".
Sample Input
110203026810555711122233344455566677753141592653589793238462643383270
Sample Output
Case 1: maximum height = 40
Case 2: maximum height = 21
Case 3: maximum height = 28
Case 4: maximum height = 342