#include<stdio.h>#include<string.h>#define N 1001#include<algorithm>using namespace std;struct node{ int x,y,z;}dot[N];int sum[N];int cmp(node a,node b){ if(a.x>b.x)return 1; else if(a.x==b.x){ if(a.y<b.y)return 1; else return 0; } else return 0;}int main(){ int n,cas=1; int a,b,c; while(scanf("%d",&n)!=EOF){ if(n==0)break; int i=0; for(int j=0;j<n;j++){ scanf("%d%d%d",&a,&b,&c); dot[i].x=a;dot[i].y=b;dot[i].z=c;i++; dot[i].x=b;dot[i].y=c;dot[i].z=a;i++; dot[i].x=a;dot[i].y=c;dot[i].z=b;i++; dot[i].x=b;dot[i].y=a;dot[i].z=c;i++; dot[i].x=c;dot[i].y=b;dot[i].z=a;i++; dot[i].x=c;dot[i].y=a;dot[i].z=b;i++; } int maxx=0; sort(dot,dot+n*6,cmp); memset(sum,0,sizeof(sum)); for(int i=0;i<n*6;i++){ int min=0; for(int j=0;j<i;j++){ if(dot[i].y<dot[j].y&&min<sum[j]){ min=sum[j]; } } sum[i]=dot[i].z+min; if(sum[i]>maxx) maxx=sum[i]; } printf("Case %d: maximum height = %d\n",cas,maxx);cas++; } return 0;}