#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for(int i = 0; i < n; ++i)
#define vi vector<int>
#define all(c) (c).begin(), (c).end()

template <typename T> T hungarian(vector<vector<T>> &A) {
    const T infty = numeric_limits<T>::max();
    const int N = (int)A.size();
    const int M = (int)A[0].size();
    vector<int> P(M), way(M);
    vector<T> U(N, 0), V(M, 0), minV;
    vector<bool> used;

    for(int i = 1; i < N; i++) {
        P[0] = i;
        minV.assign(M, infty);
        used.assign(M, false);
        int j0 = 0;
        while(P[j0] != 0) {
            int i0 = P[j0], j1 = 0;
            used[j0] = true;
            T delta = infty;
            for(int j = 1; j < M; j++) {
                if(used[j]) continue;
                T curr = A[i0][j] - U[i0] - V[j];
                if(curr < minV[j]) minV[j] = curr, way[j] = j0;
                if(minV[j] < delta) delta = minV[j], j1 = j;
            }
            for(int j = 0; j < M; j++) {
                if(used[j])
                    U[P[j]] += delta, V[j] -= delta;
                else
                    minV[j] -= delta;
            }
            j0 = j1;
        }
        do {
            P[j0] = P[way[j0]];
            j0 = way[j0];
        } while(j0 != 0);
    }
    return -V[0];
}

int main() {
    while(1) {
        int n;
        cin >> n;
        if(!n) return 0;
        vi x(n), y(n), z(n);
        rep(i, n) cin >> x[i] >> y[i] >> z[i];
        vi id(n);
        rep(i, n) {
            vi v{x[i], y[i], z[i]};
            sort(all(v));
            x[i] = v[0], y[i] = v[1], z[i] = v[2];
        }
        vector<vi> a(n + 1, vi(n + 1));
        int ans = 0;
        rep(i, n) rep(j, n) {
            if(x[i] < x[j] and y[i] < y[j] and z[i] < z[j]) { a[i + 1][j + 1] = -x[i] * y[i] * z[i]; }
        }
        rep(i, n) ans += x[i] * y[i] * z[i];
        cout << ans + hungarian(a) << endl;
    }
}
