import java.util.Arrays; import java.util.Comparator; import java.util.Scanner; import java.util.TreeSet; class Main { public static void main(String[] args) { new Main().run(); } void run() { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[][] S = new int[N][3]; for (int i = 0; i < N; ++i) { int[] a = new int[3]; for (int j = 0; j < 3; ++j) { a[j] = sc.nextInt(); } Arrays.sort(a); for (int j = 0; j < 3; ++j) { S[i][j] = a[j]; } } Arrays.sort(S, new Comparator() { @Override public int compare(int[] arg0, int[] arg1) { if (arg0[0] != arg1[0]) return Integer.compare(arg0[0], arg1[0]); else if (arg0[1] != arg1[0]) return Integer.compare(arg0[1], arg1[1]); else return Integer.compare(arg0[2], arg1[2]); } }); int[] dp = new int[N]; dp[0] = 1; for (int i = 1; i < N; ++i) { for (int j = 0; j < i; ++j) { if (S[i][0] > S[j][1] && S[i][1] > S[j][1] && S[i][2] > S[j][2]) { dp[i] = Math.max(dp[i], dp[j] + 1); } } } int ans = 0; for (int i = 0; i < N; ++i) { ans = Math.max(ans, dp[i]); } System.out.println(ans); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }