#include<iostream>
#include<string>
#include<cassert>
#include<algorithm>
#include<map>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<set>
#include<sstream>
#include<fstream>
#include<cstdio>
#include<queue>
#include<unordered_map>
#include<tuple>
#include<complex>
#include<memory>
using namespace std;
const int maxn = 30 + 5;
int cubic[maxn][3];
int d[maxn][3];
bool vis[maxn][3];
int n;
void getab(int cubic[3], int& x, int& y,int &z, int i)
{
int cnt = 0;
if (cnt == i)
++cnt;
x = cubic[cnt++];
if (cnt == i)
++cnt;
y = cubic[cnt++];
z = cubic[i];
}
int dp(int i,int f)
{
if (vis[i][f])return d[i][f];
vis[i][f] = 1;
int& ans = d[i][f];
int x, y, z;
getab(cubic[i], x, y, z, f);
for (int idx = 0; idx < n; ++idx)
{
for (int face = 0; face < 3; ++face)
{
int cx, cy, cz;
getab(cubic[idx], cx, cy, cz, face);
if (cx < x && cy < y)
ans = max(ans, dp(idx, face) + z);
}
}
return ans;
}
int main()
{
//freopen("input.txt", "r", stdin);
int kase = 0;
while (scanf("%d", &n) && n)
{
memset(d, 0, sizeof(d));
memset(vis, 0, sizeof(vis));
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < 3; ++j)
scanf("%d", &cubic[i][j]);
sort(cubic[i], cubic[i] + 3);
for (int f = 0; f < 3; ++f)
{
d[i][f] = cubic[i][f];
}
}
int ans = 0;
for (int i = 0; i < n; ++i)
{
for (int f = 0; f < 3; ++f)
{
ans = max(ans, dp(i, f));
}
}
cout << "Case " << ++kase << ": maximum height = ";
cout << ans << endl;
}
}
04-27