import collections
N = int(input())
lsg = collections.defaultdict(list)
node = []
for i in range(N):
    r1,c1,r2,c2 = map(int,input().split())
    lsg[(r1,c1)].append((r2,c2))
    lsg[(r2,c2)].append((r1,c1))
    node.append((r1,c1))
    node.append((r2,c2))
used = collections.defaultdict(lambda :False)
ans = True
for x,y in node:
    if used[(x,y)]:
        continue
    d = collections.deque([(x,y)])
    roop = 0
    while d:
        x,y = d.pop()
        if used[(x,y)]:
            continue
        used[(x,y)] = True
        c = 0
        for xn,yn in lsg[(x,y)]:
            if used[(xn,yn)]:
                c += 1
                continue
            d.append((xn,yn))
        if c >= 2:
            roop += c-1
    if roop >= 2:
        ans = False
print('YES' if ans else 'NO')