#include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; struct Box { int x; int y; int z; Box(int x = -1, int y = -1, int z = -1) { this->x = x; this->y = y; this->z = z; } bool operator<(const Box &n) const { return max(x, max(y, z)) > max(n.x, max(n.y, n.z)); } }; bool can_include(Box &b1, Box &b2) { if (b1.x > b2.x && b1.y > b2.y && b1.z > b2.z) return true; if (b1.x > b2.x && b1.y > b2.z && b1.z > b2.y) return true; if (b1.x > b2.y && b1.y > b2.x && b1.z > b2.z) return true; if (b1.x > b2.y && b1.y > b2.z && b1.z > b2.x) return true; if (b1.x > b2.z && b1.y > b2.y && b1.z > b2.x) return true; if (b1.x > b2.z && b1.y > b2.x && b1.z > b2.y) return true; return false; } int main() { int N; cin >> N; vector box_list; for (int i = 0; i < N; ++i) { Box box; cin >> box.x >> box.y >> box.z; box_list.push_back(box); } sort(box_list.begin(), box_list.end()); ll dp[N + 1][N + 1]; memset(dp, 0, sizeof(dp)); ll ans = 1; for (int i = 1; i <= N; ++i) { Box &box = box_list[i - 1]; dp[i][i] = 1; for (int j = 1; j < i; ++j) { dp[i][j] = dp[i - 1][j]; Box &p_box = box_list[j - 1]; if (not can_include(p_box, box)) continue; /* fprintf(stderr, "(%d, %d, %d) -> (%d, %d, %d)\n", p_box.x, p_box.y, p_box.z, box.x, box.y, box.z); */ dp[i][i] = max(dp[i][i], dp[i][j] + 1); ans = max(ans, dp[i][i]); } } cout << ans << endl; return 0; }