A0 = [list(map(int,input().split())) for _ in range(4)] A = [] N = [0] * 16 q = [] for i in range(16): h = i // 4 w = i % 4 A.append(A0[h][w] - 1) if A[i] == i: N[i] = 1 if A[i] == -1: q.append(i) while q: x = q.pop() if x >= 4: if A[x - 4] == x: N[x] = 1 q.append(x-4) continue if x < 12: if A[x + 4] == x: N[x] = 1 q.append(x+4) continue if 0 < x % 4: if A[x - 1] == x: N[x] = 1 q.append(x-1) continue if x % 4 < 3: if A[x+1] == x: N[x] = 1 q.append(x+1) if sum(N) == 15: print("Yes") else: print("No")