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; long a, b, c; for (var i = 0; i < N - 2; i++) { a = A[i]; for (var j = i + 1; j < N - 1; j++) { b = A[j]; for (var k = j + 1; k < N; k++) { c = A[k]; 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 } }