#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define FOR(i,a,b) for(ll i=(a);i<(b);++i) #define ALL(v) (v).begin(), (v).end() #define p(s) cout<<(s)< void vprint(T &V){ for(auto v : V){ cout << v << " "; } cout << endl; } ll A[4][4]; int main(){ cin.tie(0); ios::sync_with_stdio(false); // input FOR(i, 0, 4){ cin >> A[i][0]; cin >> A[i][1]; cin >> A[i][2]; cin >> A[i][3]; } ll empty_i; ll empty_j; FOR(i, 0, 4){ FOR(j, 0, 4){ if(A[i][j]==0){ empty_i = i; empty_j = j; } } } while(true){ // 上下左右を見る FOR(i, 0, 4){ // 空白部分にあるべき数字 ll number = 4 * empty_i + empty_j + 1; ll next_i = empty_i + dy[i]; ll next_j = empty_j + dx[i]; bool found = false; if(0<=next_i && next_i < 4 && 0<=next_j && next_j < 4 && A[next_i][next_j]==number){ swap(A[empty_i][empty_j], A[next_i][next_j]); empty_i = next_i; empty_j = next_j; found = true; } if(!found){ goto HERE; } } } HERE: // last check FOR(i, 0, 4){ FOR(j, 0, 4){ ll number = 4 * i + j + 1; if(i==3 && j==3){ number = 0; } if(A[i][j]!=number){ p_no(); return 0; } } } p_yes(); return 0; }