n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for l in range(min(n, k) + 1):
    for r in range(min(n, k) - l + 1):
        bag = sorted(v[:l] + v[n - r:])
        minus = sum(vi for vi in bag[:k - l - r] if vi < 0)
        ans = max(ans, sum(bag) - minus)
print(ans) n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k v = list(map(int, input().split())) v list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ans = 0 ans 0 for l in range(min(n, k) + 1):
    for r in range(min(n, k) - l + 1):
        bag = sorted(v[:l] + v[n - r:])
        minus = sum(vi for vi in bag[:k - l - r] if vi < 0)
        ans = max(ans, sum(bag) - minus) l range(min(n, k) + 1) range min(n, k) + 1 min(n, k) min n k 1 for r in range(min(n, k) - l + 1):
        bag = sorted(v[:l] + v[n - r:])
        minus = sum(vi for vi in bag[:k - l - r] if vi < 0)
        ans = max(ans, sum(bag) - minus) r range(min(n, k) - l + 1) range min(n, k) - l + 1 min(n, k) - l min(n, k) min n k l 1 bag = sorted(v[:l] + v[n - r:]) bag sorted(v[:l] + v[n - r:]) sorted v[:l] + v[n - r:] v[:l] v :l l v[n - r:] v n - r: n - r n r minus = sum(vi for vi in bag[:k - l - r] if vi < 0) minus sum(vi for vi in bag[:k - l - r] if vi < 0) sum vi ans = max(ans, sum(bag) - minus) ans max(ans, sum(bag) - minus) max ans sum(bag) - minus sum(bag) sum bag minus print(ans) print ans n, k = map(int, input().split()) map(int, input().split()) n k = map(int, input().split()) map(int, input().split()) k bag = sorted(v[:l] + v[n - r:]) sorted(v[:l] + v[n - r:]) bag v = list(map(int, input().split())) list(map(int, input().split())) v ans = max(ans, sum(bag) - minus) max(ans, sum(bag) - minus) ans ans = 0 0 ans minus = sum(vi for vi in bag[:k - l - r] if vi < 0) sum(vi for vi in bag[:k - l - r] if vi < 0) minus
n, k = map(int, input().split())
v = list(map(int, input().split()))

ans = 0
for l in range(min(n, k) + 1):
    for r in range(min(n, k) - l + 1):
        bag = sorted(v[:l] + v[n - r:])
        minus = sum(vi for vi in bag[:k - l - r] if vi < 0)
        ans = max(ans, sum(bag) - minus)
print(ans)
