#include using namespace std; int a[16]; int geta(int x,int y) { if (x < 0 || x >= 4 || y < 0 || y >= 4) { return 0; } else { return a[x + y * 4]; } } int main() { for (int i = 0;i < 16;i++) { cin >> a[i]; } while (true) { bool b = false; for (int i = 0;i < 16;i++) { if (a[i] == 0) { int dx[] = { 1,0,-1,0 }; int dy[] = { 0,1,0,-1 }; for (int j = 0;j < 4;j++) { int x = i % 4 + dx[j]; int y = i / 4 + dy[j]; if (geta(x, y) == i + 1) { a[x + y * 4] = 0; a[i] = i + 1; b = true; break; } } } } if (!b) { break; } } for (int i = 0;i < 15;i++) { if (i + 1 != a[i]) { cout << "No" << endl; return 0; } } if (0 != a[15]) { cout << "No" << endl; } else { cout << "Yes" << endl; } return 0; }