#include using namespace std; typedef pair< int, int > Pi; const int vy[] = {0, 1, 0, -1}, vx[] = {1, 0, -1, 0}; map< Pi, Pi > futon; map< Pi, int > head; bool check(const Pi &point) { head[point] = 1; head[futon[point]] = -1; bool flag = true; for(int i = 0; i < 4 && flag; i++) { const int nx = point.first + vx[i], ny = point.second + vy[i]; if(make_pair(nx, ny) == futon[point]) continue; if(head.find({nx, ny}) != head.end()) { if(head[{nx, ny}] == -1) flag = false; } else if(futon.find({nx, ny}) != futon.end()) { if(!check({nx, ny})) flag = false; } } for(int i = 0; i < 4 && flag; i++) { const int nx = futon[point].first + vx[i], ny = futon[point].second + vy[i]; if(make_pair(nx, ny) == point) continue; if(head.find({nx, ny}) != head.end()) { if(head[{nx, ny}] == 1) flag = false; } else if(futon.find({nx, ny}) != futon.end()) { if(!check(futon[{nx, ny}])) flag = false; } } return (flag); } int main() { int N, R[100]; cin >> N; vector< pair< int, int > > vv; int a[100], b[100], c[100], d[100]; for(int i = 0; i < N; i++) { int x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2; futon[{x1, y1}] = {x2, y2}; futon[{x2, y2}] = {x1, y1}; } sort(begin(vv), end(vv)); while(!futon.empty()) { auto decide = *futon.begin(); if(head.find(decide.first) == head.end()) { if(!check(decide.first)) break; } futon.erase(futon.begin()); } if(futon.empty()) cout << "YES" << endl; else cout << "NO" << endl; }