import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int[][]p = new int[4][4]; for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { p[i][j] = scan.nextInt(); } } scan.close(); int r0 = 0; int c0 = 0; int cnt = 0; for(int i = 0; i < 4; i++) { for(int j = 0; j < 4; j++) { int t = p[i][j]; if(t == 0) { r0 = i; c0 = j; continue; } int l = len(t, i, j); if(l >= 2) { System.out.println("No"); System.exit(0); }else if(l == 1) { cnt ++; } } } int []dx = {1, -1, 0, 0}; int []dy = {0, 0, 1, -1}; boolean flag = true; int[]a = new int[16]; for(int i = 0; i < cnt; i++) { flag = true; for(int j = 0; j < 4; j++) { int nr = dx[j] + r0; int nc = dy[j] + c0; if(nr < 0 || nc < 0 || nr > 3 || nc > 3) { continue; } int k = p[nr][nc]; int l = len(k, nr, nc); if(l == 1) { int t = p[r0][c0]; p[r0][c0] = k; p[nr][nc] = t; r0 = nr; c0 = nc; flag = false; if(a[t] != 0) { System.out.println("No"); System.exit(0); }else { a[t] = 1; } break; } } if(flag) { System.out.println("No"); System.exit(0); } } System.out.println(cnt); System.out.println("Yes"); } static int len(int n, int nr, int nc) { int r = n / 4; int c = n % 4; if(c == 0) { c = 3; r -= 1; }else { c -= 1; } int l = Math.abs(nr - r) + Math.abs(nc - c); return l; } }