import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); int[] x = new int[N]; int[] y = new int[N]; int[] z = new int[N]; for(int i = 0; i < N; i++) { int a = sc.nextInt(); int b = sc.nextInt(); int c = sc.nextInt(); int[] arr = {a, b, c}; Arrays.sort(arr); x[i] = arr[0]; y[i] = arr[1]; z[i] = arr[2]; } int[] bigN = new int[N]; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { if(x[i] < x[j] && y[i] < y[j] && z[i] < z[j]) bigN[i]++; } } int[] c = bigN.clone(); Arrays.sort(c); int[] ord = new int[N]; boolean[] used = new boolean[N]; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { if(!used[j] && bigN[j] == c[i]) { used[j] = true; ord[i] = j; break; } } } // dp[i]は箱ord[i]を最も内部にしたときの入れ子の最大値 int[] dp = new int[N]; dp[0] = 1; for(int i = 1; i < N; i++) { int a = 0; for(int j = 0; j < i; j++) { if(x[ord[i]] < x[ord[j]] && y[ord[i]] < y[ord[j]] && z[ord[i]] < z[ord[j]]) a = Math.max(a, dp[j]); } dp[i] = a + 1; } int ans = 0; for(int i = 0; i < N; i++) { ans = Math.max(ans, dp[i]); } System.out.println(ans); } }