#include #include #include #include #include #include using namespace std; int f[4][4]; bool inrage(int i, int j){ return 0 <= i && i <= 3 && 0 <= j && j <= 3; } bool valid(int i, int j, int num){ bool result = false; if(inrage(i, j-1)){ if(f[i][j-1] == num) result = true; } if(inrage(i, j+1)){ if(f[i][j+1] == num) result = true; } if(inrage(i+1, j)){ if(f[i+1][j] == num) result = true; } if(inrage(i-1, j)){ if(f[i-1][j] == num) result = true; } if(f[i][j] == num) result = true; return result; } int main() { for(int i=0; i<4; i++){ for(int j=0; j<4; j++){ cin >> f[i][j]; } } bool result = true; for(int i=0; i<4; i++){ for(int j=0; j<4; j++){ int num = (4*i + j + 1)%16; if(!valid(i,j, num )){ result = false; } } } if(result) cout << "Yes" << endl; else cout << "No" << endl; return 0; }