#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#include <iomanip>//io控制头文件 cout<<fixed<<setprecision(3)<<ans<<"\n";
#define ms(x,n) memset(x,n,sizeof x)
using namespace std;
const int inf=0x3f3f3f3f;
const int N=30*6+10;
int dp[N];
int n;
struct node{
int l,s,h;
node(int l,int s,int h): l(l),s(s),h(h){}
bool operator <(const node &c) const{
if(l==c.l) return s<c.s;
return l<c.l;
}
};
vector<node> p;
int main()
{
int kk=0;
while(cin>>n&&n){
p.clear();
ms(dp,0);
int a,b,c;
for(int i=1;i<=n;i++){
cin>>a>>b>>c;
p.push_back(node(a,b,c));
p.push_back(node(a,c,b));
p.push_back(node(b,a,c));
p.push_back(node(b,c,a));
p.push_back(node(c,a,b));
p.push_back(node(c,b,a));
}
sort(p.begin(),p.end());
int px=p.size();
int ans=0;
for(int i=0;i<px;i++){
dp[i]=p[i].h;
for(int j=i-1;j>=0;j--){
if(p[j].l<p[i].l&&p[j].s<p[i].s&&dp[j]+p[i].h>dp[i]) //!路径优化+智能选边dp
dp[i]=dp[j]+p[i].h; //!dp,每次只加1
}
ans=max(ans,dp[i]);
}
printf("Case %d: maximum height = %d\n",++kk,ans);
}
return 0;
}
11-13
781