#include using namespace std; bool inside(int a, int b, int alim, int blim){ return 0 <= a && a < alim && 0 <= b && b < blim; } int main(){ int a[4][4], pi, pj, dd[] = {0, 1, 0, -1, 0}; for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++){ cin >> a[i][j]; if(a[i][j] == 0){ pi = i; pj = j; continue; } bool f = a[i][j] == (4 * i + j + 1) % 16; for(int k = 0; k < 4; k++){ int ni = i + dd[k], nj = j + dd[k + 1]; if(inside(ni, nj, 4, 4)) f |= a[i][j] == (4 * ni + nj + 1) % 16; } if(!f){ cerr << i << ' ' << j << endl; cout << "No" << endl; return 0; } } while((4 * pi + pj + 1) % 16){ bool f = true; for(int i = 0; i < 4; i++){ int ni = pi + dd[i], nj = pj + dd[i + 1]; if(inside(ni, nj, 4, 4) && a[ni][nj] == (4 * pi + pj + 1) % 16){ swap(a[pi][pj], a[ni][nj]); pi = ni; pj = nj; f = false; break; } } if(f) break; } bool f = true; for(int i = 0; i < 4; i++) for(int j = 0; j < 4; j++) f &= a[i][j] == (4 * i + j + 1) % 16; cout << (f ? "Yes" : "No") << endl; }