n , k = map(int, input().split())
v = list(map(int,input().split()))
ma = float('INF')*(-1)
m = min(n,k)
for i in range(m+1):
    for j in range(m+1-i):
        vl=v[:i]
        vr=v[n-j:]
        ans = sum(vl)+sum(vr)
        vb=vl+vr
        vb.sort()
        m2 = min(k-i-j, len(vb))
        for l in range(m2):
            if vb[l]<0:
                ans-=vb[l]
            else:
                break
        ma = max(ans,ma)
if ma<0:
    ma = 0
print(ma) 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 ma = float('INF')*(-1) ma float('INF')*(-1) float('INF') float 'INF' -1 m = min(n,k) m min(n,k) min n k for i in range(m+1):
    for j in range(m+1-i):
        vl=v[:i]
        vr=v[n-j:]
        ans = sum(vl)+sum(vr)
        vb=vl+vr
        vb.sort()
        m2 = min(k-i-j, len(vb))
        for l in range(m2):
            if vb[l]<0:
                ans-=vb[l]
            else:
                break
        ma = max(ans,ma) i range(m+1) range m+1 m 1 for j in range(m+1-i):
        vl=v[:i]
        vr=v[n-j:]
        ans = sum(vl)+sum(vr)
        vb=vl+vr
        vb.sort()
        m2 = min(k-i-j, len(vb))
        for l in range(m2):
            if vb[l]<0:
                ans-=vb[l]
            else:
                break
        ma = max(ans,ma) j range(m+1-i) range m+1-i m+1 m 1 i vl=v[:i] vl v[:i] v :i i vr=v[n-j:] vr v[n-j:] v n-j: n-j n j ans = sum(vl)+sum(vr) ans sum(vl)+sum(vr) sum(vl) sum vl sum(vr) sum vr vb=vl+vr vb vl+vr vl vr vb.sort() vb.sort vb sort m2 = min(k-i-j, len(vb)) m2 min(k-i-j, len(vb)) min k-i-j k-i k i j len(vb) len vb for l in range(m2):
            if vb[l]<0:
                ans-=vb[l]
            else:
                break
         l range(m2) range m2 if vb[l]<0:
                ans-=vb[l]
            else:
                break
         vb[l]<0 vb[l] vb l 0 ans-=vb[l] ans vb[l] vb l break ma = max(ans,ma) ma max(ans,ma) max ans ma if ma<0:
    ma = 0 ma<0 ma 0 ma = 0 ma 0 print(ma) print ma v = list(map(int,input().split())) list(map(int,input().split())) v vl=v[:i] v[:i] vl ans-=vb[l] vb[l] ans ma = float('INF')*(-1) float('INF')*(-1) ma m = min(n,k) min(n,k) m vr=v[n-j:] v[n-j:] vr k = map(int, input().split()) map(int, input().split()) k ma = 0 0 ma ans = sum(vl)+sum(vr) sum(vl)+sum(vr) ans m2 = min(k-i-j, len(vb)) min(k-i-j, len(vb)) m2 ma = max(ans,ma) max(ans,ma) ma n , k = map(int, input().split()) map(int, input().split()) n vb=vl+vr vl+vr vb
n , k = map(int, input().split())
v = list(map(int,input().split()))
ma = float('INF')*(-1)
m = min(n,k)
for i in range(m+1):
    for j in range(m+1-i):
        vl=v[:i]
        vr=v[n-j:]
        ans = sum(vl)+sum(vr)
        vb=vl+vr
        vb.sort()
        m2 = min(k-i-j, len(vb))
        for l in range(m2):
            if vb[l]<0:
                ans-=vb[l]
            else:
                break
        ma = max(ans,ma)
if ma<0:
    ma = 0
print(ma)
