//#define _GLIBCXX_DEBUG #include #define rep(i, n) for(int i=0; i; using vs = vector; using vi = vector; using vvi = vector; template using PQ = priority_queue; template using PQG = priority_queue, greater >; const int INF = 100010001; const ll LINF = (ll)INF*INF*10; template inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);} template inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);} template istream &operator>>(istream &is, pair &p) { return is >> p.first >> p.second;} template ostream &operator<<(ostream &os, const pair &p) { return os << p.first << ' ' << p.second;} const int N = 10000; //head inline int num(int i, int j) {return i*100 + j;} int n; vi G[N]; bitset bits; bool able = true; inline void add(int i, int j) { G[i].emplace_back(j); G[j].emplace_back(i); } bool dfs(int i, int j) { //cout << i << ' ' << j << endl; for(int &ne:G[i]) if(ne != j and ne != -1) { if(bits.test(ne)) return false; bits.set(ne); if(!dfs(ne, i)) { if(bits.test(i)) return false; bits.flip(ne); bits.set(i); auto itr = find(all(G[ne]), i); ne = -1; *itr = -1; } } return true; } int main() { ios::sync_with_stdio(false); cin.tie(0); cin >> n; rep(i, n) { int r0, c0, r1, c1; cin >> r0 >> c0 >> r1 >> c1; add(num(r0-1, c0-1), num(r1-1, c1-1)); } rep(i, N) { if(!bits.test(i)) { if(!dfs(i, -1)) { able = false; break; } } } cout << (able?"YES":"NO") << endl; }