using System.Linq; using System; public class Hello { static void Main() { var n = int.Parse(Console.ReadLine().Trim()); string[] line = Console.ReadLine().Trim().Split(' '); var a = Array.ConvertAll(line, int.Parse); getAns(n, a); } static void getAns(int n, int[] a) { var count = 0; var ansi = 0; for (int i = 0; i < n; i++) { if (check(n, a, i)) { ansi = i; count++; } } Console.WriteLine(count == 1 ? a[ansi] : -1); } static bool check(int n, int[] a, int t) { var c = new int[] { 0, 2, 4, 5, 7, 9, 11 }; var d = a[t]; foreach (var x in a) { var y = x - d; if (y < 0) y += 12; y %= 12; if (!c.Contains(y)) return false; } return true; } }