import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;
public class Main {
public static int maxStackHeight(Box arr[], int n) {
Box rot[] = new Box[3 * n];
int index = 0;
for (int i = 0; i < n; i++) {
rot[index] = arr[i];
index++;
rot[index] = new Box(arr[i].getW(), Math.min(arr[i].getH(),
arr[i].getD()), Math.max(arr[i].getH(), arr[i].getD()));
index++;
rot[index] = new Box(arr[i].getD(), Math.min(arr[i].getH(),
arr[i].getW()), Math.max(arr[i].getH(), arr[i].getW()));
index++;
}
n = 3 * n;
Arrays.sort(rot, new Comparator<Box>() {
public int compare(Box o1, Box o2) {
return (Integer.valueOf(o2.d * o2.w)).compareTo(Integer
.valueOf(o1.d * o1.w));
}
});
int dp[] = new int[n];
for (int i = 0; i < n; i++)
dp[i] = rot[i].h;
for (int i = 1; i < n; i++)
for (int j = 0; j < i; j++)
if (rot[i].w < rot[j].w && rot[i].d < rot[j].d
&& dp[i] < dp[j] + rot[i].h) {
dp[i] = dp[j] + rot[i].h;
}
Arrays.sort(dp);
return dp[dp.length - 1];
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = 0, i = 0;
while (true) {
n = sc.nextInt();
if (n == 0)
break;
else {
Box arr[] = new Box[n];
for (i = 0; i < n; i++)
arr[i] = new Box(sc.nextInt(), sc.nextInt(), sc.nextInt());
System.out.println(maxStackHeight(arr, n));
}
}
}
}
class Box {
int h;
int w;
int d;
public Box(int h, int w, int d) {
super();
this.h = h;
this.w = w;
this.d = d;
}
public int getH() {
return h;
}
public void setH(int h) {
this.h = h;
}
public int getW() {
return w;
}
public void setW(int w) {
this.w = w;
}
public int getD() {
return d;
}
public void setD(int d) {
this.d = d;
}
}
Please help. Thanks in advance.