#include #define FOR(i,a,b) for (int i=(a);i<(b);i++) #define FORR(i,a,b) for (int i=(a);i>=(b);i--) #define pb push_back using namespace std; typedef long long ll; typedef pair pii; typedef pair ti; typedef vector vi; typedef set si; const int inf = 1e9; const int mod = 1e9+7; vector sat[100][2][2]; vector li[10201]; main(){ cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; FOR(i, 0, n){ int a, b; FOR(j, 0, 2){ cin >> a >> b; a = a * 101 + b; li[a].pb(pii(i, j)); } FOR(j, 0, 2){ FOR(k, 0, 2){ sat[i][j][k].pb(ti(pii(i, 1-j), 1-k)); } } } FOR(i, 0, 10201){ FOR(j, 0, li[i].size()){ int f, s; f = li[i][j].first; s = li[i][j].second; FOR(k, 0, li[i].size()){ if(j==k)continue; int _f, _s; _f = li[i][k].first; _s = li[i][k].second; sat[f][s][1].pb(ti(pii(_f, _s), 0)); } } } set y; queue q; ti bad, tmp; vector tmpv; FOR(i, 0, n)FOR(j, 0, 2)FOR(k, 0, 2){ y.clear(); q.push(ti(pii(i, j), k)); bad = ti(pii(i, j), 1-k); while(!q.empty()){ tmp = q.front(); q.pop(); y.insert(tmp); if(tmp == bad){ cout << "NO" << endl; return 0; } tmpv = sat[tmp.first.first][tmp.first.second][tmp.second]; for(vector::iterator itr = tmpv.begin(); itr != tmpv.end(); itr++){ if(y.find(*itr) == y.end()){ q.push(*itr); } } } } cout << "YES" << endl; }