using System; using System.Collections.Generic; using System.Linq; namespace No228 { class MainClass { private static Tuple FindZero(List values) { for (int i = 0; i < values.Count; i++) { if (values [i] == 0) { return new Tuple(i %4, i / 4); } } throw new Exception (); } private static bool IsNear(int expected, int[] values) { var y = (expected-1) / 4; var x = (expected-1) % 4; var shifts = new []{ new Tuple (0, 0), new Tuple (1, 0), new Tuple (-1, 0), new Tuple (0, 1), new Tuple (0, -1), }; foreach (var element in shifts) { var cx = x + element.Item1; var cy = y + element.Item2; if (cx >= 0 && cx < 4) { if (cy >= 0 && cy < 4) { if (values [cy * 4 + cx] == expected) { return true; } } } } return false; } public static void Main (string[] args) { List list = new List (); for (int i = 0; i < 4; i++) { var line = Console.ReadLine ().Split(' ').Select(value=>Convert.ToInt32(value)); list.AddRange (line); } var initial = Enumerable.Range (1, 15).Concat (new[]{ 0 }).ToList (); for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { var index = y * 4 + x; if (list [index] != 0) { if(!IsNear(initial[index], list.ToArray())){ Console.WriteLine ("No"); return; } } } } int swapCount = 0; for (int y = 0; y < 4; y++) { for (int x = 0; x < 4; x++) { var index = y * 4 + x; if (list [index] != 0) { if (list [index] != initial [index]) { swapCount++; } } } } var point = FindZero (list); swapCount += (3 - point.Item1); swapCount += (3 - point.Item2); if (swapCount % 2 == 0) { Console.WriteLine ("Yes"); return; } Console.WriteLine ("No"); } } }