Problem: Matryoshka

Matryoshka is a famous Russian folk craft doll. Matryoshka can be divided into upper and lower parts, and when opened, there is another smaller doll inside. The nesting structure is such that when the small doll that appears is opened, a smaller doll is contained.

<image>


You found an unusually shaped matryoshka doll on your trip and bought N dolls. The shape of the i-th doll is a rectangular parallelepiped of xi × yi × zi.

After watching Matryoshka for a while, you are about to put away Matryoshka. Before that, I want to reduce the space required by storing some dolls in another. When storing a doll, one other doll can be stored only in the doll that has not yet stored any doll. However, only the dolls that are stored directly are counted, and the doll that contains the doll can be stored in another doll.

The stored doll becomes invisible from the outside. However, the following conditions must be met.

* The doll may rotate, but each side of the rectangular parallelepiped is parallel to any side of the other rectangular parallelepiped.
* After rotation, the length of the doll on the side to be stored is shorter for each of the lengths of the corresponding sides.
* At most one doll can be stored directly in one doll



Since the volume of the closet is limited, we want to minimize the sum of the volumes of the dolls that can be seen from the outside. Your job is to create a program that finds the minimum sum of the volumes of the dolls that are visible from the outside, which can be achieved by repeating the operation of storing the dolls any number of times.

Input

The input consists of multiple datasets. The maximum number of data sets does not exceed 50. Each dataset is represented in the following format.

> N
> x1 y1 z1
>::
>::
> xN yN zN
>

Each dataset consists of N + 1 rows, and the first row of the dataset is given the integer N, which represents the number of dolls. In the i-th line of the following N lines, three integers xi, yi, and zi representing the size of the i-th doll are given, separated by a half-width space. These integers satisfy 1 ≤ N, xi, yi, zi ≤ 100.

> The end of the input is represented by a single zero line.

> ### Output

For each data set, output the minimum value of the sum of the volumes of the dolls that can be seen from the outside in one line.

> ### Sample Input


2
one two Three
4 2 3
3
2 5 2
3 3 4
5 5 5
Five
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
Five
1 1 1
2 1 1
3 1 1
4 1 1
5 1 1
Ten
3 1 4
1 5 9
2 6 5
3 5 8
9 7 9
3 2 3
8 4 6
2 6 4
3 3 8
3 2 7
0


Output for Sample Input


twenty four
145
125
15
864





Example

Input

2
1 2 3
4 2 3
3
2 5 2
3 3 4
5 5 5
5
1 1 1
2 2 2
3 3 3
4 4 4
5 5 5
5
1 1 1
2 1 1
3 1 1
4 1 1
5 1 1
10
3 1 4
1 5 9
2 6 5
3 5 8
9 7 9
3 2 3
8 4 6
2 6 4
3 3 8
3 2 7
0


Output

24
145
125
15
864

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define MAX 301
#define inf 1<<29
#define linf (1e16)
#define eps (1e-8)
#define Eps (1e-12)
#define mod 1000000007
#define pi acos(-1.0)
#define phi (1.0+sqrt(5.0))/2.0
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define pld(a) printf("%.10Lf\n",(ld)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define Unique(v) v.erase(unique(all(v)),v.end())
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<int,double> pid;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<pii> vpi;

struct edge{ int to,cap,cost,rev; };

int v;
vector<edge> e[MAX];
int h[MAX];
int dist[MAX];
int prevv[MAX],preve[MAX];

void add_edge(int from,int to,int cap,int cost){
  e[from].push_back((edge){to,cap,cost,(int)e[to].size()});
  e[to].push_back((edge){from,0,-cost,(int)e[from].size()-1});
}
 
int min_cost_flow(int s,int t,int f){
  int res=0;
  fill(h,h+v,0);
  fill(prevv,prevv+MAX,0);
  fill(preve,preve+MAX,0);
  while(f>0){
    priority_queue<pii,vector<pii>,greater<pii> > pq;
    fill(dist,dist+v,inf);
    dist[s]=0;
    pq.push(pii(0,s));
    while(pq.size()){
      pii p=pq.top();
      pq.pop();
      int u=p.second;
      if(dist[u]<p.first)continue;
      for(int i=0;i<e[u].size();i++){
        edge &E=e[u][i];
        if(E.cap>0 && dist[E.to]>dist[u]+E.cost+h[u]-h[E.to]){
          dist[E.to]=dist[u]+E.cost+h[u]-h[E.to];
          prevv[E.to]=u;
          preve[E.to]=i;
          pq.push(pii(dist[E.to],E.to));
        }
      }
    }
    if(dist[t]==inf)return -1;
    for(int i=0;i<v;i++)h[i]+=dist[i];
 
    int d=f;
    for(int u=t;u!=s;u=prevv[u]){
      d=min(d,e[prevv[u]][preve[u]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int u=t;u!=s;u=prevv[u]){
      edge &E=e[prevv[u]][preve[u]];
      E.cap-=d;
      e[u][E.rev].cap+=d;
    }
  }
  return res;
}

int n;
vector<vector<int> > dolls;
int vol[MAX];

void init(){
  dolls.clear();
  FOR(i,0,MAX)e[i].clear();
}

bool containable(vector<int> a,vector<int> b){
  FOR(i,0,3)if(b[i]<=a[i])return false;
  return true;
}

int solve(){
  int sum = 0;
  FOR(i,0,n){
    vol[i] = dolls[i][0]*dolls[i][1]*dolls[i][2];
    sum += vol[i];
  }
  FOR(i,0,n){
    FOR(j,0,n){
      if(i==j)continue;
      if(containable(dolls[i],dolls[j]))add_edge(i,j+n,1,-vol[i]);
    }
  }
  int s=n+n,t=s+1,u=t+1;;
  v = t+2;
  FOR(i,0,n)add_edge(s,i,1,0);
  FOR(i,0,n)add_edge(i+n,t,1,0);
  add_edge(s,u,inf,0);
  add_edge(u,t,inf,0);
  int res = min_cost_flow(s,t,inf);
  return sum+res;
}

int main()
{
  while(cin>>n && n){
    init();
    FOR(i,0,n){
      vector<int> v;
      v.resize(3);
      cin>>v[0]>>v[1]>>v[2];
      sort(all(v));
      dolls.pb(v);
    }
    cout<<solve()<<endl;
  }
  return 0;
}