#include #include #include #include void solve() { int sx, sy; std::vector> pos(15); std::vector> goal(4, std::vector(4)); for (int x = 0; x < 4; ++x) { for (int y = 0; y < 4; ++y) { goal[x][y] = x * 4 + y; int a; std::cin >> a; --a; if (a < 0) { sx = x; sy = y; } else { pos[a] = std::make_pair(x, y); } } } goal[3][3] = -1; while (goal[sx][sy] != -1) { int a = goal[sx][sy]; int x, y; std::tie(x, y) = pos[a]; if (std::abs(x - sx) + std::abs(y - sy) > 1) { std::cout << "No" << std::endl; return; } pos[a] = std::make_pair(sx, sy); sx = x, sy = y; } for (int a = 0; a < 15; ++a) { int x, y; std::tie(x, y) = pos[a]; if (goal[x][y] != a) { std::cout << "No" << std::endl; return; } } std::cout << "Yes" << std::endl; return; } int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); solve(); return 0; }