a = [list(map(int, input().split())) for _ in range(4)] c = [[(i+j)%16 for i in range(1, 5)] for j in range(0,16,4)] dy = [-1, 0, 1, 0] dx = [0, -1, 0, 1] loop = True while loop: for y in range(4): for x in range(4): if a[y][x] == 0: for k in range(4): ty = dy[k] + y tx = dx[k] + x if 0 <= ty < 4 and 0 <= tx < 4 and a[ty][tx] == c[y][x]: a[y][x], a[ty][tx] = a[ty][tx], a[y][x] break else: loop = False print('Yes' if a == c else 'No')