#include #include #include #include #include #include #include #include #include #include using namespace std; vector> goal = { {1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}, {13, 14, 15, 0} }; int dx[4] = {0,0,1,-1}; int dy[4] = {1,-1,0,0}; int main(){ vector> v(4, vector(4)); for(int i=0; i<4; i++){ for(int j=0; j<4; j++){ cin >> v[i][j]; } } int zero = -1; auto x = v; vector> e(16); bool ok = true; for(int i=0; i<4; i++){ for(int j=0; j<4; j++){ if(v[i][j] == 0){ zero = i*4 + j; } if(i==3 && j == 3) continue; if(v[i][j] == goal[i][j]) continue; bool tmp = false; for(int k=0; k<4; k++){ int yy = i+dy[k]; int xx = j+dx[k]; if(xx<0 || xx>=4 || yy<0 || yy>=4) continue; if(v[yy][xx] == goal[i][j]){ e[i*4 + j].push_back(yy*4 + xx); tmp = true; } } if(tmp == false){ ok = false; } } } for(int i=0; i<16; i++){ if(e[i].size() > 1) ok = false; } if(ok == false){ cout << "No" << endl; return 0; } int pos = zero; while(pos != 15){ if(e[pos].size() == 0) break; int next = e[pos][0]; swap(v[pos/4][pos%4], v[next/4][next%4]); pos = next; } if(v == goal){ cout << "Yes" << endl; }else{ cout << "No" << endl; } return 0; }