import java.io.BufferedReader; import java.io.InputStreamReader; public class No278 { public static void main(String[] args) { try { int goal[][] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 }, { 9, 10, 11, 12 }, { 13, 14, 15, 0 } }; BufferedReader br = new BufferedReader(new InputStreamReader( System.in)); int start[][] = new int[4][4]; for (int i = 0; i < 4; i++) { start[i] = strToIntArray(br.readLine()); } String str = "Yes"; for (int i = 0; i < 4; i++) { for (int j = 0; j < 4; j++) { if (goal[i][j] == 0) { continue; } for (int j2 = 0; j2 < 4; j2++) { for (int k = 0; k < 4; k++) { // 距離が2以上離れてたらむりだろ if (goal[i][j] == start[j2][k]) { if (1 < Math.abs(i - j2) + Math.abs(j - k)) { str = "No"; } } } } } } int start2[] = new int[16]; int count = 0; for (int[] is : start) { for (int i : is) { if (i != 0) { start2[count] = i; } else { start2[count] = 100; } count++; } } if (!checkright15Puzzle(start2)) { str = "No"; } System.out.println(str); } catch (Exception e) { e.printStackTrace(); System.err.println("Error:" + e.getMessage()); } } static boolean checkright15Puzzle(int[] x) { if (x == null) { return false; } int N = x.length; int count = 0; // ループの条件に注意 for (int i = 0; i < N; i++) { if (x[i] != 1) { for (int j = i; j < N; j++) { if (x[j] == i) { int swap = x[i]; x[i] = i; x[j] = swap; count++; break; } } } } return count % 2 == 0; } static int[] strToIntArray(String S) { String[] strArray = S.split(" "); int[] intArray = new int[strArray.length]; for (int i = 0; i < strArray.length; i++) { intArray[i] = Integer.parseInt(strArray[i]); } return intArray; } }