using System; using static System.Console; using System.Linq; using System.Collections.Generic; class Program { static int NN => int.Parse(ReadLine()); static long[] NList => ReadLine().Split().Select(long.Parse).ToArray(); public static void Main() { Solve(); } static void Solve() { var c = NList; var (n, m, k) = (c[0], c[1], c[2]); var a = NList; var set = new HashSet(); for (var i = 0; i <= n; ++i) for (var j = 0; j <= n; ++j) for (var p = 0; p <= n; ++p) { var ai = i == n ? 0 : a[i]; var aj = j == n ? 0 : a[j]; var ap = p == n ? 0 : a[p]; set.Add(ai + aj + ap); } var list = new List(set); list.Sort(); var pos = list.Count - 1; var ans = 0L; for (var i = 0; i < list.Count; ++i) { while (pos >= 0 && list[i] + list[pos] > m) --pos; if (pos >= 0) ans = Math.Max(ans, list[i] + list[pos]); } WriteLine(ans); } }