#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;
using ll = long long;


#include<atcoder/dsu>
#include<map>
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n;
    cin>>n;
    atcoder::dsu uf(100*100);
    map<pair<int,int>,int> memo;
    for(int i = 0;i<n;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        a--;b--;c--;d--;
        int ni = a * 100 + b;
        int nj = c * 100 + d;
        uf.merge(ni,nj);
        memo[{a,b}]++;
    }
    bool fn = false;
    for(auto now:uf.groups()){
        int cnt = 0;
        for(auto e:now){
            int a = e / 100;
            int b = e % 100;
            cnt += memo[{a,b}];
        }
        int sz = now.size();
        if(cnt<=sz) continue;
        fn = true;
    }
    if(fn) cout<<"NO\n";
    else cout<<"YES\n";
}