def main(): # Read the input grid = [] for _ in range(4): grid.extend(list(map(int, input().split()))) # Determine the initial positions (original puzzle state) initial_positions = {1: (0,0), 2: (0,1), 3: (0,2), 4: (0,3), 5: (1,0), 6: (1,1), 7: (1,2), 8: (1,3), 9: (2,0), 10: (2,1), 11: (2,2), 12: (2,3), 13: (3,0), 14: (3,1), 15: (3,2), 0: (3,3)} # Check condition 1: Manhattan distance for each tile except 0 must be 0 or 1 for num in range(1, 16): idx = grid.index(num) target_row = idx // 4 target_col = idx % 4 initial_row, initial_col = initial_positions[num] dx = abs(target_row - initial_row) dy = abs(target_col - initial_col) if dx + dy > 1: print("No") return # Check solvability under classic rules # For the solvability, we need to compute the parity of the inversion count and the blank row movement flat = [num for num in grid if num != 0] inv_count = 0 for i in range(len(flat)): for j in range(i + 1, len(flat)): if flat[i] > flat[j]: inv_count += 1 # Find the position of 0 (blank) in the initial and target grids initial_blank_row = 3 # 0 is at (3,3) in initial target_blank_row = 0 for i in range(16): if grid[i] == 0: target_blank_row = i // 4 # Calculate the row difference for the blank tile row_diff = target_blank_row - initial_blank_row if (inv_count + row_diff) % 2 != 0: print("No") return print("Yes") if __name__ == "__main__": main()