N = int(input()) XYZ = [] for i in range(N): xyz = list(map(int,input().split())) xyz.sort() XYZ.append(xyz) E = [[] for _ in range(N)] D = [0] * N for i in range(N-1): x1,y1,z1 = XYZ[i] for j in range(i+1,N): x2,y2,z2 = XYZ[j] if x1 > x2 and y1 > y2 and z1 > z2: E[j].append(i) D[i] += 1 if x1 < x2 and y1 < y2 and z1 < z2: E[i].append(j) D[j] += 1 Q = [] for i in range(N): if D[i] == 0: Q.append(i) dp = [1] * N Q2 = [] while Q: while Q: x = Q.pop() for y in E[x]: dp[y] = max(dp[y],dp[x]+1) D[y] -= 1 if D[y] == 0: Q2.append(y) Q,Q2 = Q2,Q print(max(dp))