N, K = map(int, input().split())
V = [0]*N
*V, = map(int, input().split())

ans = []
for i in range(N+1):
    for j in range(N+1):
        if i+j > min(N, K): continue
        out = V[:i] + V[N-j:]
        out.sort()
        r = 0
        while i+j+r < K and r < len(out):
            if out[r] < 0: r += 1
            else: break
        ans.append(sum(out[r:]))

print(max(ans)) N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K V = [0]*N V [0]*N [0] 0 N *V, = map(int, input().split()) *V V map(int, input().split()) map int input().split() ().split () input split ans = [] ans [] for i in range(N+1):
    for j in range(N+1):
        if i+j > min(N, K): continue
        out = V[:i] + V[N-j:]
        out.sort()
        r = 0
        while i+j+r < K and r < len(out):
            if out[r] < 0: r += 1
            else: break
        ans.append(sum(out[r:])) i range(N+1) range N+1 N 1 for j in range(N+1):
        if i+j > min(N, K): continue
        out = V[:i] + V[N-j:]
        out.sort()
        r = 0
        while i+j+r < K and r < len(out):
            if out[r] < 0: r += 1
            else: break
        ans.append(sum(out[r:])) j range(N+1) range N+1 N 1 if i+j > min(N, K): continue
         i+j > min(N, K) i+j i j min(N, K) min N K out = V[:i] + V[N-j:] out V[:i] + V[N-j:] V[:i] V :i i V[N-j:] V N-j: N-j N j out.sort() out.sort out sort r = 0 r 0 while i+j+r < K and r < len(out):
            if out[r] < 0: r += 1
            else: break
         i+j+r < K and r < len(out) i+j+r < K i+j+r i+j i j r K r < len(out) r len(out) len out if out[r] < 0: r += 1
            else: break
         out[r] < 0 out[r] out r 0 ans.append(sum(out[r:])) ans.append ans append sum(out[r:]) sum out[r:] out r: r print(max(ans)) print max(ans) max ans K = map(int, input().split()) map(int, input().split()) K out = V[:i] + V[N-j:] V[:i] + V[N-j:] out ans = [] [] ans r = 0 0 r N, K = map(int, input().split()) map(int, input().split()) N V = [0]*N [0]*N V
N, K = map(int, input().split())
V = [0]*N
*V, = map(int, input().split())

ans = []
for i in range(N+1):
    for j in range(N+1):
        if i+j > min(N, K): continue
        out = V[:i] + V[N-j:]
        out.sort()
        r = 0
        while i+j+r < K and r < len(out):
            if out[r] < 0: r += 1
            else: break
        ans.append(sum(out[r:]))

print(max(ans))