using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; namespace AtCoder.A { public class Program { public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); } private static object GetResult() { var N = ReadLong(); var A = ReadLongs(); var min = long.MaxValue; for (var i = 0; i < N - 2; i++) { for (var j = i + 1; j < N - 1; j++) { for (var k = j + 1; k < N; k++) { var a = A[i]; var b = A[j]; var c = A[k]; if (a == b || b == c || c == a) continue; if (b < a && b < c || b > a && b > c) { min = Math.Min(min, a + b + c); } } } } return min == long.MaxValue ? -1 : min; } #region Console public static string ReadText() { return Console.ReadLine(); } public static List ReadTexts() { return Console.ReadLine().Split(' ').ToList(); } public static long ReadLong() { return long.Parse(Console.ReadLine()); } public static List ReadLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); } #endregion } }