#pragma GCC optimize("O3") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using P = pair; using T = tuple; template inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;} template inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;} constexpr int MOD = 1e9 + 7; constexpr int inf = 1e9; constexpr long long INF = 1e18; #define all(a) (a).begin(), (a).end() int dx[] = {1, 0, -1, 0}; int dy[] = {0, 1, 0, -1}; bool can_put[20][5][20][5]; int main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin>>n; vector> abc(n, vector(3)); for(int i=0; i>abc[i][j]; } for(int pi=0; pi v1; for(int i=0; i<3; i++){ if(i != ph) v1.emplace_back(abc[pi][i]); } vector v2; for(int i=0; i<3; i++){ if(i != nh) v2.emplace_back(abc[ni][i]); } sort(all(v1)); sort(all(v2)); if((v1[0] >= v2[0] && v1[1] >= v2[1]) || (v1[1] >= v2[0] && v1[0] >= v2[1])) can_put[pi][ph][ni][nh] = true; } } } } vector>> dp((1<>(n, vector(3, -1))); for(int i=0; i