n, k = map(int, input().split())
v = [int(i) for i in input().split()]
ans = 0
for a in range(min(n, k) + 1):
    pa, va = v[:a], v[a:]
    for b in range(min(n, k) - a + 1):
        pb = pa + va[-b:] if b > 0 else pa
        pb.sort()
        s = sum(pb)
        ans = max(s, ans)
        for c in range(min(k - a - b, a + b)):
            s -= pb[c]
            ans = max(s, ans)
print(ans) n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k int(i) for i in input().split() for i in input().split() i input().split() ().split () input split for i in input().split() int(i) int i v = [int(i) for i in input().split()] v [int(i) for i in input().split()] ans = 0 ans 0 for a in range(min(n, k) + 1):
    pa, va = v[:a], v[a:]
    for b in range(min(n, k) - a + 1):
        pb = pa + va[-b:] if b > 0 else pa
        pb.sort()
        s = sum(pb)
        ans = max(s, ans)
        for c in range(min(k - a - b, a + b)):
            s -= pb[c]
            ans = max(s, ans) a range(min(n, k) + 1) range min(n, k) + 1 min(n, k) min n k 1 pa, va = v[:a], v[a:] pa v[:a] v :a a va v[a:] v a: a for b in range(min(n, k) - a + 1):
        pb = pa + va[-b:] if b > 0 else pa
        pb.sort()
        s = sum(pb)
        ans = max(s, ans)
        for c in range(min(k - a - b, a + b)):
            s -= pb[c]
            ans = max(s, ans) b range(min(n, k) - a + 1) range min(n, k) - a + 1 min(n, k) - a min(n, k) min n k a 1 pb = pa + va[-b:] if b > 0 else pa pb pa + va[-b:] if b > 0 else pa b > 0 b 0 pa + va[-b:] pa va[-b:] va -b: -b b pa pb.sort() pb.sort pb sort s = sum(pb) s sum(pb) sum pb ans = max(s, ans) ans max(s, ans) max s ans for c in range(min(k - a - b, a + b)):
            s -= pb[c]
            ans = max(s, ans) c range(min(k - a - b, a + b)) range min(k - a - b, a + b) min k - a - b k - a k a b a + b a b s -= pb[c] s pb[c] pb c ans = max(s, ans) ans max(s, ans) max s ans print(ans) print ans ans = 0 0 ans ans = max(s, ans) max(s, ans) ans pa, va = v[:a], v[a:] v[:a] pa ans = max(s, ans) max(s, ans) ans s -= pb[c] pb[c] s v = [int(i) for i in input().split()] [int(i) for i in input().split()] v s = sum(pb) sum(pb) s va = v[:a], v[a:] v[a:] va n, k = map(int, input().split()) map(int, input().split()) n pb = pa + va[-b:] if b > 0 else pa pa + va[-b:] if b > 0 else pa pb k = map(int, input().split()) map(int, input().split()) k
n, k = map(int, input().split())
v = [int(i) for i in input().split()]
ans = 0
for a in range(min(n, k) + 1):
    pa, va = v[:a], v[a:]
    for b in range(min(n, k) - a + 1):
        pb = pa + va[-b:] if b > 0 else pa
        pb.sort()
        s = sum(pb)
        ans = max(s, ans)
        for c in range(min(k - a - b, a + b)):
            s -= pb[c]
            ans = max(s, ans)
print(ans)
