#include #include #include #include #include #include #include #include using namespace std; #define REP(i,a,b) for(int i=a;i<(int)b;i++) #define rep(i,n) REP(i,0,n) typedef long long ll; int dx[4] = {-1,0,1,0}; int dy[4] = {0,-1,0,1}; constexpr bool inrange(int x, int y) { return 0<=x&&x<4&&0<=y&&y<4; } int main() { set used; int a[4][4], x, y; rep(i, 4) rep(j, 4) { cin >> a[i][j]; if(a[i][j] == 0) x = j, y = i; } while(1) { bool ok = false; rep(i, 4) { int nx = x+dx[i], ny = y+dy[i]; if(!inrange(nx, ny)) { continue; } if(used.count(a[ny][nx])) { continue; } if(y*4+x+1 != a[ny][nx]) { continue; } ok = true; used.insert(a[ny][nx]); swap(a[ny][nx], a[y][x]); x = nx, y = ny; } if(!ok) { break; } } bool ok = true; rep(i, 4) rep(j, 4) { if(i == 3 && j == 3) { break; } if(i*4+j+1 != a[i][j]) { ok = false; } } cout << (ok ? "Yes\n" : "No\n"); return 0; }