//////////////////////////////////////// /////////////////////////////
// Monkey and banana
// Convert each square into three. Sort them first, and then use the DP of N ^ 2.
# Include <iostream>
# Include <algorithm>
Using namespace STD;
Struct Block
{
Int X;
Int y;
Int height;
} BL [100];
Void maxmin (Int & A, Int & B, Int & C)
{
If (A <B & A <C)
If (B <C );
Else swap (B, c );
Else if (B <C & B <)
{
Swap (A, B );
If (B <C );
Else swap (B, c );
}
Else
{
Swap (a, c );
If (B <C );
Else swap (B, c );
}
}
Bool comp (const block & A, const block & B)
{
If (A. X! = B. X) Return (A. x <B. X );
Else return (A. Y <= A. Y );
}
Int main ()
{
Int I, j, n, a, B, c, Count = 1, Max;
While (CIN> N & n! = 0)
{
For (I = 1; I <= 3 * n; I = I + 3)
{
Cin> A> B> C;
Maxmin (A, B, C );
BL [I]. x =;
BL [I]. Y = B;
BL [I]. Height = C;
BL [I + 1]. x =;
BL [I + 1]. Y = C;
BL [I + 1]. Height = B;
BL [I + 2]. x = B;
BL [I + 2]. Y = C;
BL [I + 2]. Height =;
}
BL [0]. x = bl [0]. Y = bl [0]. Height = 0;
Sort (BL, BL + 3 * n + 1, comp );
For (I = 1; I <= 3 * n; I ++)
{
Max = 0;
For (j = 0; j <I; j ++)
{
If (BL [I]. x> BL [J]. X & BL [I]. y> BL [J]. Y & BL [J]. height> MAX)
Max = bl [J]. height;
}
BL [I]. height + = max;
}
Max = 0;
For (I = 1; I <= 3 * n; I ++)
If (BL [I]. Height> MAX)
Max = bl [I]. height;
Cout <"case" <count <": maximum height =" <max <Endl;
Count ++;
}
Return 0;
}