import sys import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def main(): n = int(input()) XYZ = [] X = [] for i in range(n): temp = list(map(int, input().split())) temp.sort() x, y, z = temp XYZ.append((x, y, z)) X.append(x) X = sorted(list(set(X))) d = {} for i, x in enumerate(X): d[x] = i N = len(d) YZ = [[] for i in range(N)] for x, y, z in XYZ: YZ[d[x]].append((y, z)) from collections import defaultdict dp = defaultdict(lambda:1) mod =10**9 for y, z in YZ[0]: dp[y*mod+z] = 1 dp[z*mod+y] = 1 for i in range(1, N): nx = defaultdict(lambda:1) for k, v in dp.items(): nx[k] = max(nx[k], v) for ny, nz in YZ[i]: nk = ny*mod+nz nx[nk] = 1 nk = nz*mod+ny nx[nk] = 1 for k, v in dp.items(): y, z = divmod(k, mod) if y < ny and z < nz: nk = ny*mod+nz nx[nk] = max(nx[nk], dp[k]+1) if y < nz and z < ny: nk = nz*mod+ny nx[nk] = max(nx[nk], dp[k]+1) dp = nx ans = 1 for k, v in dp.items(): ans = max(ans, v) print(ans) if __name__ == '__main__': main()