import java.util.*; class Main { static int N; static int[] r0, c0, r1, c1; public static void main(String[] args) { Scanner sc = new Scanner(System.in); N = sc.nextInt(); r0 = new int[N]; c0 = new int[N]; r1 = new int[N]; c1 = new int[N]; DJSet ds = new DJSet(100 * 100); for (int i = 0; i < N; ++i) { r0[i] = sc.nextInt() - 1; c0[i] = sc.nextInt() - 1; r1[i] = sc.nextInt() - 1; c1[i] = sc.nextInt() - 1; ds.setUnion(r0[i] + c0[i] * 100, r1[i] + c1[i] * 100); } for (int i = 0; i < 100; ++i) { for (int j = 0; j < 100; ++j) { if (ds.edgeNumber[ds.root(i + j * 100)] >= -ds.upper[ds.root(i + j * 100)] + 1) { System.out.println("NO"); return; } } } System.out.println("YES"); } static class DJSet { int n; int[] upper; int[] edgeNumber; public DJSet(int n) { this.n = n; upper = new int[n]; edgeNumber = new int[n]; Arrays.fill(upper, -1); } boolean equiv(int x, int y) { return root(x) == root(y); } int root(int x) { return upper[x] < 0 ? x : (upper[x] = root(upper[x])); } void setUnion(int x, int y) { x = root(x); y = root(y); if (x != y) { if (upper[x] < upper[y]) { int tmp = x; x = y; y = tmp; } upper[y] += upper[x]; upper[x] = y; edgeNumber[y] += edgeNumber[x]; } ++edgeNumber[y]; } } static void tr(Object... objects) { System.out.println(Arrays.deepToString(objects)); } }