# 0の上下左右に、0のところにあるべき駒があるなら動かす、なければNo # 動かして全盤面正しければYes # 繰り返す A = [] for i in range(4): temp = list(map(int, input().split())) A.append(temp) for j in range(4): if A[i][j] == 0: zero = (i, j) B = [[0]*4 for i in range(4)] num = 1 for i in range(4): for j in range(4): if i == 3 and j == 3: continue B[i][j] = num num += 1 from collections import deque que = deque() que.append(zero) d = [[1, 0], [-1, 0], [0, 1], [0, -1]] while que: ci, cj = que.popleft() for di, dj in d: if 0 <= ci+di < 4 and 0 <= cj+dj < 4: if A[ci+di][cj+dj] == B[ci][cj]: A[ci][cj], A[ci+di][cj+dj] = A[ci+di][cj+dj], A[ci][cj] que.append((ci+di, cj+dj)) break #print('A', A) if A == B: print('Yes') exit() print('No')