using System; using System.Linq; using System.Collections.Generic; class Program { static void Main() { var a = new int[16]; for(int i = 0; i < 4; i++) { var tmp = ria(4); for(int j = 0; j < 4; j++) { a[i * 4 + j] = tmp[j]; } } int inv = 0; var ans = "Yes"; for(int i = 0; i < 16; i++) { for(int j= i; j < 16; j++) { if (a[i] > a[j] && a[j] != 0) inv++; } if (a[i] == 0) inv += (15 - i) / 4; if (a[i] != 0 && !(a[i] == i + 2 || a[i] == i + 1 || a[i] == i || a[i] == i + 5 || a[i] == i - 3)) ans = "No"; } if (inv % 2 == 1) ans = "No"; Console.WriteLine(ans); } #region Scan static int ri() { return int.Parse(Console.ReadLine()); } static long rl() { return long.Parse(Console.ReadLine()); } static double rd() { return double.Parse(Console.ReadLine()); } static string rs() { return Console.ReadLine(); } static int[] ria(int n) { return Console.ReadLine().Trim().Split().Select(int.Parse).ToArray(); } static long[] rla(int n) { return Console.ReadLine().Trim().Split().Select(long.Parse).ToArray(); } static double[] rda(int n) { return Console.ReadLine().Trim().Split().Select(double.Parse).ToArray(); } static string[] rsa(int n) { return Console.ReadLine().Trim().Split(); } static void mul(out int a, out int b) { var arr = ria(2); a = arr[0]; b = arr[1]; } public void mul(out int a, out int b, out int c) { var arr = ria(3); a = arr[0]; b = arr[1]; c = arr[2]; } public void mul(out int a, out int b, out int c, out int d) { var arr = ria(4); a = arr[0]; b = arr[1]; c = arr[2]; d = arr[3]; } #endregion }