import std.algorithm; import std.array; import std.ascii; import std.container; import std.conv; import std.math; import std.numeric; import std.range; import std.stdio; import std.string; import std.typecons; void log(A...)(A arg) { stderr.writeln(arg); } int size(T)(in T s) { return cast(int)s.length; } const int[] dy = [-1, 0, 1, 0]; const int[] dx = [0, 1, 0, -1]; void main() { int N; readf("%d\n", &N); auto D = new int[][](112, 112); auto C = new int[][](112, 112); foreach (i; 0 .. N) { int sy, sx, gy, gx; readf("%d %d %d %d\n", &sy, &sx, &gy, &gx); if (sy == gy) { // -> assert(gx - sx == 1); D[sy][sx] = 1; D[gy][gx] = 3; } else { assert(sx == gx); // v assert(gy - sy == 1); D[sy][sx] = 2; D[gy][gx] = 0; } C[sy][sx]++; C[gy][gx]++; } void dfs(int y, int x) { // (y, x)縺九i蜃コ縺ヲ縺・k霎コ縺・蛟九@縺九↑縺・↑繧峨€√◎繧後r蜀榊クー逧・↓豸亥悉 if (C[y][x] != 1) return; C[y][x] = 0; int k = D[y][x]; int ny = y + dy[k]; int nx = x + dx[k]; assert(C[ny][nx] >= 1); C[ny][nx]--; dfs(ny, nx); } foreach (int y; 0 .. 112) { foreach (int x; 0 .. 112) { dfs(y, x); } } int count(int y, int x) { int c = 0; if (C[y][x] % 2 == 1) { c++; } C[y][x] = 0; foreach (k; 0 .. 4) { int ny = y + dy[k]; int nx = x + dx[k]; if (ny < 0 || ny >= 112) continue; if (nx < 0 || nx >= 112) continue; if (C[ny][nx] == 0) continue; assert(C[ny][nx] != 1); c += count(ny, nx); } return c; } foreach (int y; 0 .. 112) { foreach (int x; 0 .. 112) { if (C[y][x] == 0) continue; assert(C[y][x] != 1); if (count(y, x) >= 1) { writeln("NO"); return; } } } writeln("YES"); }