#include using namespace std; typedef long long ll; #define REP(i,n) FOR(i,0,n) #define FOR(i,a,b) for(ll i=a;i vi; typedef vector> vvi; const ll INF = (1ll << 30); typedef pair pii; typedef vector> Graph; typedef vector vpii; bool contains(vi a,vi b) { sort(ALL(b)); do { if(a[0]>b[0]&&a[1]>b[1]&&a[2]>b[2]) return true; } while(next_permutation(ALL(b))); return false; } int main() { ll N; cin>>N; Graph G(N); vi incoming(N); { vvi v(N,vi(3)); REP(i,N) cin>>v[i][0]>>v[i][1]>>v[i][2]; REP(i,N) { REP(j,N) { if(contains(v[i],v[j])) { G[i].PB(j); incoming[j]++; } } } } ll ans=0; REP(root,N) { vi cnt(N,0); vi in = incoming; queue q; q.push(root); cnt[root]=1; while(q.size()) { ll from=q.front(); q.pop(); for(ll to:G[from]) { in[to]--; if(in[to]==0) q.push(to); cnt[to]=max(cnt[to],cnt[from]+1); } } for(ll i:cnt) ans=max(ans,i); cout<