#include using namespace std; #define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++) #define ALL(x) x.begin(),x.end() template bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; } template bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; } typedef long long ll; int N; const int M = 3; int dp [1001] [1001]; const int INF = 1e9; int main() { scanf("%d",&N); vector< vector > A(N,vector(M)); FOR(i,0,N){ FOR(j,0,M){ scanf("%d",&A [i] [j]); } sort(ALL(A [i])); } sort(ALL(A)); reverse(ALL(A)); fill(dp [0],dp [N + 1],-INF); FOR(i,0,N){ dp [i + 1] [i] = 1; } FOR(i,1,N) FOR(j,0,i) if(dp [i] [j] >= 0){ chmax(dp [i + 1] [j],dp [i] [j]); bool ok = true; FOR(k,0,M){ ok &= A [j] [k] > A [i] [k]; } if(ok){ chmax(dp [i + 1] [i],dp [i] [j] + 1); } } int ans = 0; FOR(i,0,N){ chmax(ans,dp [N] [i]); } printf("%d\n",ans); return 0; }