import java.util.*; import java.io.*; public class Main { static int[][] dp; static Box[] boxes; public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int n = Integer.parseInt(br.readLine()); dp = new int[n][n + 1]; boxes = new Box[n + 1]; for (int i = 0; i < n; i++) { boxes[i] = new Box(br.readLine()); Arrays.fill(dp[i], -1); } boxes[n] = new Box(new int[]{Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE}); Arrays.sort(boxes); System.out.println(dfw(n - 1, n)); } static int dfw(int idx, int bidx) { if (idx < 0) { return 0; } if (dp[idx][bidx] != -1) { return dp[idx][bidx]; } dp[idx][bidx] = dfw(idx - 1, bidx); if (boxes[bidx].smaller(boxes[idx])) { dp[idx][bidx] = Math.max(dp[idx][bidx], dfw(idx - 1, idx) + 1); } return dp[idx][bidx]; } static class Box implements Comparable { int[] arr = new int[3]; public Box(int[] arr) { this.arr = arr; Arrays.sort(arr); } public Box(String line) { String[] lines = line.split(" ", 3); for (int i = 0; i < 3; i++) { arr[i] = Integer.parseInt(lines[i]); } Arrays.sort(arr); } public int compareTo(Box another) { for (int i = 0; i <= 2; i++) { if (arr[i] != another.arr[i]) { return arr[i] - another.arr[i]; } } return 0; } public boolean equals(Object o) { Box another = (Box)o; for (int i = 0; i < 3; i++) { if (arr[i] != another.arr[i]) { return false; } } return true; } public boolean smaller(Box another) { for (int i = 0; i < 3; i++) { if (arr[i] <= another.arr[i]) { return false; } } return true; } } }