#include #include #include #include #define repeat(i,n) for (int i = 0; (i) < int(n); ++(i)) #define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) using namespace std; int main() { int n; scanf("%d", &n); vector x(n), y(n), z(n); repeat (i,n) scanf("%d%d%d", &x[i], &y[i], &z[i]); vector > g(n); vector indegree(n); repeat (i,n) { array a = {{ x[i], y[i], z[i] }}; whole(sort, a); repeat (j,n) { bool found = false; do { if (a[0] < x[j] and a[1] < y[j] and a[2] < z[j]) { found = true; } } while (whole(next_permutation, a)); if (found) { g[j].push_back(i); indegree[i] += 1; } } } vector depth(n, -1); function dfs = [&](int i, int cur_depth) { if (depth[i] < cur_depth) { depth[i] = cur_depth; for (int j : g[i]) { dfs(j, cur_depth + 1); } } }; repeat (i,n) if (indegree[i] == 0) { dfs(i, 0); } int max_depth = *whole(max_element, depth); printf("%d\n", max_depth + 1); return 0; }