# !/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines from collections import Counter N = int(readline()) m = map(int, read().split()) L = 112 graph = [[] for _ in range(L * L)] for a, b, c, d in zip(m, m, m, m): x = L * a + b y = L * c + d graph[x].append(y) graph[y].append(x) comp = [0] * (L * L) ng = False for i in range(L * L): if comp[i]: continue comp[i] = i Nv = 1 Ne = 0 stack = [i] while stack: v = stack.pop() for w in graph[v]: Ne += 1 if comp[w]: continue comp[w] = i Nv += 1 stack.append(w) Ne //= 2 if Ne > Nv: ng = True break print('NO' if ng else 'YES')