n, k = map(int, input().split())
a = list(map(int, input().split()))
b = a[::-1]
ans = 0
for i in range(1,min(n+1, k+1)):
    for j in range(i+1):
        m = i - j
        l = a[:m] + b[:j]
        ml = sorted([i for i in l if i < 0])
        pl = [i for i in l if i >= 0]
        ml = ml[min(k-i, len(ml)):]
        if ml:
            minus = sum(ml)
        else:
            minus = 0
        if pl:
            plus = sum(pl)
        else:
            plus = 0
        ans = max(ans, minus + plus)        
print(ans) n, k = map(int, input().split()) n map(int, input().split()) map int input().split() ().split () input split k a = list(map(int, input().split())) a list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split b = a[::-1] b a[::-1] a ::-1 -1 ans = 0 ans 0 for i in range(1,min(n+1, k+1)):
    for j in range(i+1):
        m = i - j
        l = a[:m] + b[:j]
        ml = sorted([i for i in l if i < 0])
        pl = [i for i in l if i >= 0]
        ml = ml[min(k-i, len(ml)):]
        if ml:
            minus = sum(ml)
        else:
            minus = 0
        if pl:
            plus = sum(pl)
        else:
            plus = 0
        ans = max(ans, minus + plus)         i range(1,min(n+1, k+1)) range 1 min(n+1, k+1) min n+1 n 1 k+1 k 1 for j in range(i+1):
        m = i - j
        l = a[:m] + b[:j]
        ml = sorted([i for i in l if i < 0])
        pl = [i for i in l if i >= 0]
        ml = ml[min(k-i, len(ml)):]
        if ml:
            minus = sum(ml)
        else:
            minus = 0
        if pl:
            plus = sum(pl)
        else:
            plus = 0
        ans = max(ans, minus + plus)         j range(i+1) range i+1 i 1 m = i - j m i - j i j l = a[:m] + b[:j] l a[:m] + b[:j] a[:m] a :m m b[:j] b :j j i for i in l if i < 0 for i in l if i < 0 i l i < 0 i 0 if i < 0 i ml = sorted([i for i in l if i < 0]) ml sorted([i for i in l if i < 0]) sorted [i for i in l if i < 0] i for i in l if i >= 0 for i in l if i >= 0 i l i >= 0 i 0 if i >= 0 i pl = [i for i in l if i >= 0] pl [i for i in l if i >= 0] ml = ml[min(k-i, len(ml)):] ml ml[min(k-i, len(ml)):] ml min(k-i, len(ml)): min(k-i, len(ml)) min k-i k i len(ml) len ml if ml:
            minus = sum(ml)
        else:
            minus = 0
         ml minus = sum(ml) minus sum(ml) sum ml minus = 0 minus 0 if pl:
            plus = sum(pl)
        else:
            plus = 0
         pl plus = sum(pl) plus sum(pl) sum pl plus = 0 plus 0 ans = max(ans, minus + plus) ans max(ans, minus + plus) max ans minus + plus minus plus print(ans) print ans k = map(int, input().split()) map(int, input().split()) k b = a[::-1] a[::-1] b ml = ml[min(k-i, len(ml)):] ml[min(k-i, len(ml)):] ml n, k = map(int, input().split()) map(int, input().split()) n l = a[:m] + b[:j] a[:m] + b[:j] l plus = sum(pl) sum(pl) plus ans = max(ans, minus + plus) max(ans, minus + plus) ans pl = [i for i in l if i >= 0] [i for i in l if i >= 0] pl m = i - j i - j m plus = 0 0 plus a = list(map(int, input().split())) list(map(int, input().split())) a minus = 0 0 minus ml = sorted([i for i in l if i < 0]) sorted([i for i in l if i < 0]) ml ans = 0 0 ans minus = sum(ml) sum(ml) minus
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = a[::-1]
ans = 0
for i in range(1,min(n+1, k+1)):
    for j in range(i+1):
        m = i - j
        l = a[:m] + b[:j]
        ml = sorted([i for i in l if i < 0])
        pl = [i for i in l if i >= 0]
        ml = ml[min(k-i, len(ml)):]
        if ml:
            minus = sum(ml)
        else:
            minus = 0
        if pl:
            plus = sum(pl)
        else:
            plus = 0
        ans = max(ans, minus + plus)        
print(ans)