/** * @FileName a.cpp * @Author kanpurin * @Created 2020.06.05 00:14:07 **/ #include "bits/stdc++.h" using namespace std; typedef long long ll; int ans; struct DAG { private: struct Edge { int to; }; std::vector> graph; bool is_dag = false; std::vector sorted; int V; public: DAG(int v) { assert(v > 0); V = v; graph.resize(v); } void add_edge(int from, int to) { graph[from].push_back({to}); } std::vector topological_sort() { std::stack sta; std::vector dist(V, 0); std::vector in(V, 0); int used_cnt = 0; for (int i = 0; i < V; i++) { for (Edge e : graph[i]) { in[e.to]++; } } for (int i = 0; i < V; i++) if (in[i] == 0) { sta.push(i); used_cnt++; } while (!sta.empty()) { int p = sta.top(); sta.pop(); sorted.push_back(p); for (Edge e : graph[p]) { int v = e.to; in[v]--; dist[v] = std::max(dist[v], dist[p] + 1); ans = max(ans,dist[v]); if (in[v] == 0) { sta.push(v); used_cnt++; } } } if (used_cnt == V) { return sorted; } else { return std::vector(0); } } vector& operator[](int x) { return graph[x]; } }; int f(vector a, vector b) { do { if (a[0] > b[0] && a[1] > b[1] && a[2] > b[2]) { return 2; } else if (a[0] < b[0] && a[1] < b[1] && a[2] < b[2]) { return 1; } } while(next_permutation(a.begin(), a.end())); return 0; } int main() { int n;cin >> n; vector> a(n,vector(3)); for (int i = 0; i < n; i++) { cin >> a[i][0] >> a[i][1] >> a[i][2]; sort(a[i].begin(), a[i].end()); } DAG g(n); for (int i = 0; i < n - 1; i++) { for (int j = i + 1; j < n; j++) { int t = f(a[i],a[j]); if (t == 1) { g.add_edge(i,j); } else if (t == 2) { g.add_edge(j,i); } } } g.topological_sort(); cout << ans + 1 << endl; return 0; }