n, k = map(int, input().split())
v = list(map(int, input().split()))
m = min(n, k)
max_score = 0
for i in range(m+1):
    for j in range(m+1-i):
        vals = v[:i] if j == 0 else v[:i] + v[-j:]
        minus = list(filter(lambda x : x < 0, vals))
        minus.sort()
        score = sum(vals) - sum(minus[:min(k - i - j, len(minus))])
        if max_score < score:
            max_score = score
print(max_score) 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 m = min(n, k) m min(n, k) min n k max_score = 0 max_score 0 for i in range(m+1):
    for j in range(m+1-i):
        vals = v[:i] if j == 0 else v[:i] + v[-j:]
        minus = list(filter(lambda x : x < 0, vals))
        minus.sort()
        score = sum(vals) - sum(minus[:min(k - i - j, len(minus))])
        if max_score < score:
            max_score = score i range(m+1) range m+1 m 1 for j in range(m+1-i):
        vals = v[:i] if j == 0 else v[:i] + v[-j:]
        minus = list(filter(lambda x : x < 0, vals))
        minus.sort()
        score = sum(vals) - sum(minus[:min(k - i - j, len(minus))])
        if max_score < score:
            max_score = score j range(m+1-i) range m+1-i m+1 m 1 i vals = v[:i] if j == 0 else v[:i] + v[-j:] vals v[:i] if j == 0 else v[:i] + v[-j:] j == 0 j 0 v[:i] v :i i v[:i] + v[-j:] v[:i] v :i i v[-j:] v -j: -j j minus = list(filter(lambda x : x < 0, vals)) minus list(filter(lambda x : x < 0, vals)) list filter(lambda x : x < 0, vals) filter lambda x : x < 0 x < 0 x 0 x vals minus.sort() minus.sort minus sort score = sum(vals) - sum(minus[:min(k - i - j, len(minus))]) score sum(vals) - sum(minus[:min(k - i - j, len(minus))]) sum(vals) sum vals sum(minus[:min(k - i - j, len(minus))]) sum minus[:min(k - i - j, len(minus))] minus :min(k - i - j, len(minus)) min(k - i - j, len(minus)) min k - i - j k - i k i j len(minus) len minus if max_score < score:
            max_score = score max_score < score max_score score max_score = score max_score score print(max_score) print max_score n, k = map(int, input().split()) map(int, input().split()) n v = list(map(int, input().split())) list(map(int, input().split())) v m = min(n, k) min(n, k) m vals = v[:i] if j == 0 else v[:i] + v[-j:] v[:i] if j == 0 else v[:i] + v[-j:] vals max_score = 0 0 max_score max_score = score score max_score k = map(int, input().split()) map(int, input().split()) k minus = list(filter(lambda x : x < 0, vals)) list(filter(lambda x : x < 0, vals)) minus score = sum(vals) - sum(minus[:min(k - i - j, len(minus))]) sum(vals) - sum(minus[:min(k - i - j, len(minus))]) score
n, k = map(int, input().split())
v = list(map(int, input().split()))
m = min(n, k)
max_score = 0
for i in range(m+1):
    for j in range(m+1-i):
        vals = v[:i] if j == 0 else v[:i] + v[-j:]
        minus = list(filter(lambda x : x < 0, vals))
        minus.sort()
        score = sum(vals) - sum(minus[:min(k - i - j, len(minus))])
        if max_score < score:
            max_score = score
print(max_score)