#include "bits/stdc++.h" using namespace std; #define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i)) #define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i)) #define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i)) static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL; typedef vector vi; typedef pair pii; typedef vector > vpii; typedef long long ll; template static void amin(T &x, U y) { if (y < x) x = y; } template static void amax(T &x, U y) { if (x < y) x = y; } int main() { int N; while (~scanf("%d", &N)) { vector> v(N); rep(i, N) { array A; for (int i = 0; i < 3; ++ i) scanf("%d", &A[i]); sort(A.begin(), A.end()); v[i] = A; } sort(v.begin(), v.end()); vector dp(N, 1); rep(i, N) { int x = dp[i]; reu(j, i + 1, N) { auto a = v[i], b = v[j]; if (a[0] < b[0] && a[1] < b[1] && a[2] < b[2]) amax(dp[j], x + 1); } } int ans = *max_element(dp.begin(), dp.end()); printf("%d\n", ans); } return 0; }