#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; int main() { int a[4][4], b[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cin >> a[j][i]; b[j][i] = (i*4+j+1)%16; } } int px, py; px = py = 3; int dx[4] = {1, 0, -1, 0}; int dy[4] = {0, -1, 0, 1}; while(true) { if (b[px][py] != a[px][py]) { bool ok = false; for (int i = 0; i < 4; i++) { int nx = px+dx[i], ny = py+dy[i]; if (nx >= 0 && ny >= 0 && nx < 4 && ny < 4 && b[nx][ny] == a[px][py]) { ok = true; swap(b[nx][ny], b[px][py]); px = nx; py = ny; break; } } if (!ok) { puts("No"); return 0; } }else { break; } } bool ok = true; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (a[j][i] != b[j][i]) { ok = false; break; } } if (!ok) break; } if (ok) { puts("Yes"); }else { puts("No"); } }