def read_data(): N = int(input()) xyz = [] for _ in range(N): x, y, z = map(int, input().split()) xyz.append((x, y, z)) xyz.append((x, z, y)) xyz.append((y, x, z)) xyz.append((y, z, x)) xyz.append((z, x, y)) xyz.append((z, y, x)) return N, xyz def solve(N, xyz): xyz.append((0, 0, 0)) xyz.sort() dp = [0] * (N * 6 + 1) for idx, (x, y, z) in enumerate(xyz): tmp = 0 for idx2 in range(idx): xx, yy, zz = xyz[idx2] if xx < x and yy < y and zz < z: if tmp < dp[idx2]: tmp = dp[idx2] dp[idx] = tmp + 1 return max(dp) - 1 N, xyz = read_data() print(solve(N, xyz))