#include using namespace std; #define fi first #define se second #define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++) #define rep(i,n) repl(i,0,n) #define each(itr,v) for(auto itr:v) #define pb(s) push_back(s) #define mp(a,b) make_pair(a,b) #define all(x) (x).begin(),(x).end() #define dbg(x) cout<<#x"="<(x).count() typedef long long ll; typedef unsigned long long ull; typedef pair P; typedef pair PPI; typedef pair PL; typedef pair PPL; #define INF INT_MAX/3 #define MAX_N 1000 int n; vector box[1111]; bool edge[1111][1111]; int mem[1111]; int dfs(int v){ if(mem[v]!=-1)return mem[v]; int res=1; rep(i,n){ if(edge[v][i])maxch(res,dfs(i)+1); } return mem[v]=res; } int main(){ cin.sync_with_stdio(false); cin>>n; rep(i,n){ box[i].resize(3); rep(j,3)cin>>box[i][j]; sort(all(box[i])); } rep(i,n)rep(j,n){ bool ok=true; rep(k,3){ if(box[i][k]>=box[j][k])ok=false; } if(ok){ edge[i][j]=true; } } int res=0; memset(mem,-1,sizeof(mem)); rep(i,n){ maxch(res,dfs(i)); } cout<