N,K =map(int, input().split())
V=list(map(int, input().split()))
res=0
for l in range(K+1):
    for r in range(K+1-l):
        if l+r>N: continue
        t=V[:l]+V[N-r:]
        t.sort()
        S=sum(t)
        for c in range(min(K-l-r,l+r)):
            if t[c]<0:
                S-=t[c]
        res=max(res,S)
print(res) 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 res=0 res 0 for l in range(K+1):
    for r in range(K+1-l):
        if l+r>N: continue
        t=V[:l]+V[N-r:]
        t.sort()
        S=sum(t)
        for c in range(min(K-l-r,l+r)):
            if t[c]<0:
                S-=t[c]
        res=max(res,S) l range(K+1) range K+1 K 1 for r in range(K+1-l):
        if l+r>N: continue
        t=V[:l]+V[N-r:]
        t.sort()
        S=sum(t)
        for c in range(min(K-l-r,l+r)):
            if t[c]<0:
                S-=t[c]
        res=max(res,S) r range(K+1-l) range K+1-l K+1 K 1 l if l+r>N: continue
         l+r>N l+r l r N t=V[:l]+V[N-r:] t V[:l]+V[N-r:] V[:l] V :l l V[N-r:] V N-r: N-r N r t.sort() t.sort t sort S=sum(t) S sum(t) sum t for c in range(min(K-l-r,l+r)):
            if t[c]<0:
                S-=t[c]
         c range(min(K-l-r,l+r)) range min(K-l-r,l+r) min K-l-r K-l K l r l+r l r if t[c]<0:
                S-=t[c]
         t[c]<0 t[c] t c 0 S-=t[c] S t[c] t c res=max(res,S) res max(res,S) max res S print(res) print res K =map(int, input().split()) map(int, input().split()) K S=sum(t) sum(t) S V=list(map(int, input().split())) list(map(int, input().split())) V res=0 0 res t=V[:l]+V[N-r:] V[:l]+V[N-r:] t res=max(res,S) max(res,S) res S-=t[c] t[c] S N,K =map(int, input().split()) map(int, input().split()) N
N,K =map(int, input().split())
V=list(map(int, input().split()))
res=0
for l in range(K+1):
    for r in range(K+1-l):
        if l+r>N: continue
        t=V[:l]+V[N-r:]
        t.sort()
        S=sum(t)
        for c in range(min(K-l-r,l+r)):
            if t[c]<0:
                S-=t[c]
        res=max(res,S)
print(res)