#include using namespace std; constexpr int N = 16; long long dp[1 << N][N][3]; bool J[N][3][N][3]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; using Cuboid = array; vector v; for (int i = 0; i < n; i++) { int a, b, c; cin >> a >> b >> c; v.push_back({a, b, c}); sort(v[i].begin(), v[i].end()); } const int B = 1 << n; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { dp[1 << i][i][j] = v[i][j]; } } auto judge = [&](int &i, int &ri, int &j, int &rj) { vector vi, vj; for (int k = 0; k < 3; k++) { if (ri != k) vi.emplace_back(v[i][k]); if (rj != k) vj.emplace_back(v[j][k]); } return vi[0] <= vj[0] && vi[1] <= vj[1]; }; for (int i = 0; i < n; i++) { for (int j = 0; j < 3; j++) { for (int k = 0; k < n; k++) { for (int l = 0; l < 3; l++) { J[i][j][k][l] = judge(i, j, k, l); } } } } for (int i = 1; i < B; i++) { vector s, t; for (int j = 0; j < n; j++) { if (i & (1 << j)) s.emplace_back(j); else t.emplace_back(j); } for (auto &j: s) { for (int k = 0; k < 3; k++) { if (!dp[i][j][k]) continue; for (auto &to: t) { for (int r = 0; r < 3; r++) { if (J[to][r][j][k]) { dp[i|(1<