N,K=map(int,input().split())
V=list(map(int,input().split()))
r=min(N,K)
ans=0
for a in range(r+1):
    for b in range(r-a+1):
        tmp,minus=0,[]
        for i in range(a):
            t=V[i]
            tmp+=t
            if t<0:
                minus.append(t)
        for j in range(b):
            t=V[N-1-j]
            tmp+=t
            if t<0:
                minus.append(t)
        tmp-=sum(sorted(minus)[:K-(a+b)])
        ans=max(ans,tmp)
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 r=min(N,K) r min(N,K) min N K ans=0 ans 0 for a in range(r+1):
    for b in range(r-a+1):
        tmp,minus=0,[]
        for i in range(a):
            t=V[i]
            tmp+=t
            if t<0:
                minus.append(t)
        for j in range(b):
            t=V[N-1-j]
            tmp+=t
            if t<0:
                minus.append(t)
        tmp-=sum(sorted(minus)[:K-(a+b)])
        ans=max(ans,tmp) a range(r+1) range r+1 r 1 for b in range(r-a+1):
        tmp,minus=0,[]
        for i in range(a):
            t=V[i]
            tmp+=t
            if t<0:
                minus.append(t)
        for j in range(b):
            t=V[N-1-j]
            tmp+=t
            if t<0:
                minus.append(t)
        tmp-=sum(sorted(minus)[:K-(a+b)])
        ans=max(ans,tmp) b range(r-a+1) range r-a+1 r-a r a 1 tmp,minus=0,[] tmp 0 minus [] for i in range(a):
            t=V[i]
            tmp+=t
            if t<0:
                minus.append(t)
         i range(a) range a t=V[i] t V[i] V i tmp+=t tmp t if t<0:
                minus.append(t)
         t<0 t 0 minus.append(t) minus.append minus append t for j in range(b):
            t=V[N-1-j]
            tmp+=t
            if t<0:
                minus.append(t)
         j range(b) range b t=V[N-1-j] t V[N-1-j] V N-1-j N-1 N 1 j tmp+=t tmp t if t<0:
                minus.append(t)
         t<0 t 0 minus.append(t) minus.append minus append t tmp-=sum(sorted(minus)[:K-(a+b)]) tmp sum(sorted(minus)[:K-(a+b)]) sum sorted(minus)[:K-(a+b)] (minus) sorted minus :K-(a+b) K-(a+b) K a+b a b ans=max(ans,tmp) ans max(ans,tmp) max ans tmp print(ans) print ans t=V[i] V[i] t t=V[N-1-j] V[N-1-j] t tmp+=t t tmp tmp+=t t tmp minus=0,[] [] minus r=min(N,K) min(N,K) r K=map(int,input().split()) map(int,input().split()) K V=list(map(int,input().split())) list(map(int,input().split())) V ans=max(ans,tmp) max(ans,tmp) ans N,K=map(int,input().split()) map(int,input().split()) N tmp,minus=0,[] 0 tmp ans=0 0 ans tmp-=sum(sorted(minus)[:K-(a+b)]) sum(sorted(minus)[:K-(a+b)]) tmp
N,K=map(int,input().split())
V=list(map(int,input().split()))
r=min(N,K)
ans=0
for a in range(r+1):
    for b in range(r-a+1):
        tmp,minus=0,[]
        for i in range(a):
            t=V[i]
            tmp+=t
            if t<0:
                minus.append(t)
        for j in range(b):
            t=V[N-1-j]
            tmp+=t
            if t<0:
                minus.append(t)
        tmp-=sum(sorted(minus)[:K-(a+b)])
        ans=max(ans,tmp)
print(ans)
