#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using ull = unsigned long long; constexpr int TEN(int n) {return (n==0)?1:10*TEN(n-1);} int main() { int a[4][4]; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { cin >> a[i][j]; a[i][j]--; if (a[i][j] == -1) a[i][j] = 15; } } using P = array; constexpr P d4[4] = { {1, 0}, {0, 1}, {-1, 0}, {0, -1}, }; while (true) { P p; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (a[i][j] == 15) { p = P{i, j}; } } } if (p == P{3, 3}) break; bool f = false; for (int i = 0; i < 4; i++) { P np = P{p[0]+d4[i][0], p[1]+d4[i][1]}; if (!(0 <= min(np[0], np[1]) and max(np[0], np[1]) <= 3)) continue; if (a[np[0]][np[1]] == p[0]*4+p[1]) { f = true; swap(a[np[0]][np[1]], a[p[0]][p[1]]); } } if (!f) break; } for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (a[i][j] != i*4+j) { cout << "No" << endl; return 0; } } } cout << "Yes" << endl; return 0; }