#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include //#include using namespace std; int main() { int t[20] = {}; int s = 0; for (int i = 0; i < 16; i++) { int x; cin >> x; x--; if (x >= 0) { int d = abs(i / 4 + x / 4) + abs(i % 4 + x % 4); if (d > 1) { cout << "No" << endl; return 0; } if(d>0)s++; } t[i] = x; } int w = -1; while (w != 15) { for (int i = 0; i < 16; i++) { if (t[i] == w) { w = i; s--; break; } } } if (s == -1)cout << "YES" << endl; else cout << "NO" << endl; return 0; }