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(); } boolean check(TreeSet C, int[] S) { int[] Sl = C.lower(S); if (Sl != null && Sl[1] < S[1]) { return true; } else { return false; } } @SuppressWarnings("unchecked") void solve(int N, int[][] S) { TreeSet[] C = new TreeSet[N]; for (int i = 0; i < N; ++i) { C[i] = new TreeSet<>(new Comparator() { @Override public int compare(int[] o1, int[] o2) { if (o1[0] != o2[0]) { return Integer.compare(o1[0], o2[0]); } else { return -Integer.compare(o1[1], o2[1]); } } }); } C[0].add(S[0]); int maxLen = 1; for (int i = 1; i < N; ++i) { int left = -1; int right = maxLen; while (right - left > 1) { int middle = (right + left) / 2; if (check(C[middle], S[i])) { left = middle; } else { right = middle; } } if (left + 1 == maxLen) { C[left + 1].add(S[i]); ++maxLen; continue; } else { int[] tmp = C[left + 1].floor(S[i]); if (tmp != null && tmp[1] == S[i][1]) continue; tmp = C[left + 1].higher(S[i]); while (tmp != null && S[i][1] <= tmp[1]) { C[left + 1].remove(tmp); tmp = C[left + 1].higher(S[i]); } C[left + 1].add(S[i]); } } System.out.println(maxLen); } 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]; a[0] = sc.nextInt(); a[1] = sc.nextInt(); a[2] = sc.nextInt(); Arrays.sort(a); S[i][0] = a[0]; S[i][1] = a[1]; S[i][2] = a[2]; } Arrays.sort(S, new Comparator() { @Override public int compare(int[] o1, int[] o2) { if (o1[0] != o2[0]) return Integer.compare(o1[0], o2[0]); else if (o1[1] != o2[1]) { return -Integer.compare(o1[1], o2[1]); } else { return -Integer.compare(o1[2], o2[2]); } } }); int[][] tmp = new int[n][2]; for (int i = 0; i < n; ++i) { tmp[i][0] = S[i][1]; tmp[i][1] = S[i][2]; } solve(n, tmp); } void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }