def root(x):
  if r[x]!=x:
    r[x]=root(r[x])
  return r[x]

def union(x,y):
  rx=root(x)
  ry=root(y)
  if rx==ry:
    return
  if rx>ry:
    rx,ry=ry,rx
  r[ry]=rx
  return

n=int(input())
L=111
r=list(range(L*L))
e=[0]*L*L
for i in range(n):
  sx,sy,tx,ty=map(int,input().split())
  s=sx*L+sy
  t=tx*L+ty
  e[s]+=1
  e[t]+=1
  union(s,t)
p=[[] for i in range(L*L)]
for i in range(L*L):
  p[root(i)]+=[i]
f=1
for l in p:
  f&=1-len(l)+sum(e[i] for i in l)//2<2
print(["NO","YES"][f])