占坑(在上课所以先不写思路了)
//#include<iostream>
//#include<stdio.h>
//using namespace std;
//typedef unsigned long long uLL;
//const uLL base1 = 131;
//const uLL base2 = 233;
//const int hmaxn=1005;
//const int lmaxn=1005;
//const int xhmaxn=55;
//const int xlmaxn=55;
//int n, m;
//char mp[hmaxn][lmaxn];
//char mpsearch[xhmaxn][xlmaxn];
//uLL has[hmaxn][lmaxn];
//uLL p1[hmaxn], p2[lmaxn];
//
//void init()
//{
// p1[0] = p2[0] = 1;
// for(int i = 1; i <= 505; i ++) {
// p1[i] = p1[i-1]*base1;
// p2[i] = p2[i-1]*base2;
// }
//}
//
//void Hash()
//{
// has[0][0] = 0;
// has[0][1] = 0;
// has[1][0] = 0;
// for(int i = 1; i <= n; i ++) { //对列进行哈希
// for(int j = 1; j <= m; j ++) {
// has[i][j] = has[i][j-1]*base1 + mp[i-1][j-1] - 'a';
// }
// }
// for(int i = 1; i <= n; i++) {
// for(int j = 1; j <= m; j ++) { //对行进行哈希
// has[i][j] = has[i-1][j]*base2 + has[i][j];
// }
// }
//}
//int check(int hash,int x,int y)
//{
// int cnt = 0;
// for(int i = x; i <= n; i ++) {
// for(int j = y; j <= m; j ++) {
// uLL k = has[i][j] - has[i-x][j]*p2[x] - has[i][j-y]*p1[y] + has[i-x][j-y]*p1[x]*p2[y];
// if(k ==hash)cnt ++;
// }
// }
// return cnt;
//}
//int main()
//{
// init();
// int k,x,y;
// int count=0;
// while(cin>>n>>m>>k>>x>>y)
// {
// count++;
// cout<<"Case "<<count<<": ";
// for(int i=0;i<n;i++)scanf("%s",mp[i]);
// Hash();
// int ans=0;
// while(k--)
// {
// int hash=0;
// int hass[xhmaxn];
// for(int i=0;i<x;i++)scanf("%s",mpsearch[i]);
// for(int i = 0; i <x; i ++) { //对列进行哈希
// hass[i]=0;
// for(int j = 0; j <y; j ++) {
// hass[i] = hass[i]*base1 +mpsearch[i][j]- 'a';
// }
// }
// for(int i = 0; i < x; i++) {
// hash= hash*base2 + hass[i];
// }
// ans+=check(hash,x,y);
// }
// cout<<ans<<endl;
// }
//}
#include<iostream>
#include<stdio.h>
#include<algorithm>
using namespace std;
const int maxn=95;
struct node{
int x, y, z;
node(int a=0, int c=0, int k=0) : x(a), y(c), z(k) {}
}miao[maxn];
int dp[maxn];
bool cmp(node a,node c)
{if(a.x=c.x)
return a.y<c.y;
else return a.x<c.x;}
int main() {
int n;int k=0;
while (cin >> n&&n) {
k++;
cout<<"Case "<<k<<": maximum height = ";
int x, y, z;
int ans = 0;
for (int i = 0; i < n; i++) {
cin >> x >> y >> z;
miao[i * 3] = node(max(x, y), min(x, y), z);
miao[i * 3 + 1] = node(max(x, z), min(x, z), y);
miao[i * 3 + 2] = node(max(y, z), min(y, z), x);
}
sort(miao, miao + n * 3, cmp);
dp[0] = 0;
for (int i = 0; i < n * 3; i++)
{dp[i] = miao[i].z;
int temp = 0;
for (int j = 0; j < i; j++) {
if (miao[j].x < miao[i].x && miao[j].y < miao[i].y) {
temp = max(temp, dp[j]);
}
}
dp[i] += temp;
ans = max(dp[i], ans);}
cout << ans << endl;
}
}