from bisect import bisect def main(): N, M, K = map(int, input().split()) *A, = map(int, input().split()) A.sort() if A[0] > 0: A = [0]+A N += 1 S = set() for i in range(N): for j in range(i, N): for k in range(j, N): S.add(A[i]+A[j]+A[k]) L = sorted(list(S)) ans = 0 for l in L: if l > M: break p = bisect(L, M-l) ans = max(ans, l+L[p-1]) print(ans) if __name__ == "__main__": main()