from queue import Queue a = sum([list(map(int, input().split())) for _ in range(4)],[]) adjacent = ( (1, 4), (0, 2, 5), (1, 3, 6), (2, 7), (0, 5, 8), (1, 4, 6, 9), (2, 5, 7, 10), (3, 6, 11), (4, 9, 12), (5, 8, 10, 13), (6, 9, 11, 14), (7, 10, 15), (8, 13), (9, 12, 14), (10, 13, 15), (11, 14) ) GOAL = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 0] class State: def __init__(self, board, space, num): self.board = board self.space = space self.num = num def BFS(start): if start == GOAL: return 'Yes' q = Queue() q.put(State(start, start.index(0), [])) while not q.empty(): a = q.get() for x in adjacent[a.space]: b = a.board[:] n = a.num[:] if b[x] in n: continue n.append(b[x]) b[a.space] = b[x] b[x] = 0 c = State(b, x, n) if b == GOAL: return 'Yes' q.put(c) return 'No' if __name__ == '__main__': print(BFS(a))