n,k = map(int,input().split())
from collections import deque
au = list(map(int,input().split()))
left = [0 for i in range(n)]
right = [0 for i in range(n)]
left[0] = au[0]
right[0] = au[-1]
ans = 0
for i in range(n-1):
    left[i+1] = left[i] + au[i+1]
    right[i+1] = right[i] + au[n-i-2]
p = min(n,k)
for a in range(p+1):
    for b in range(p+1-a):
        d = deque(au)
        x = []
        y = 0
        for i in range(a):
            u = d.popleft()
            x.append(u)
            y += u
        for j in range(b):
            v = d.pop()
            x.append(v)
            y += v
        x.sort(reverse = True)
        for ue in range(k-a-b):
            if len(x) > 0 and x[-1] < 0:
                y -= x.pop()
            else:
                break
        ans = max(ans,y)
print(ans) n,k = map(int,input().split()) n map(int,input().split()) map int input().split() ().split () input split k from collections import deque au = list(map(int,input().split())) au list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 left = [0 for i in range(n)] left [0 for i in range(n)] 0 for i in range(n) for i in range(n) i range(n) range n for i in range(n) 0 right = [0 for i in range(n)] right [0 for i in range(n)] left[0] = au[0] left[0] left 0 au[0] au 0 right[0] = au[-1] right[0] right 0 au[-1] au -1 ans = 0 ans 0 for i in range(n-1):
    left[i+1] = left[i] + au[i+1]
    right[i+1] = right[i] + au[n-i-2] i range(n-1) range n-1 n 1 left[i+1] = left[i] + au[i+1] left[i+1] left i+1 i 1 left[i] + au[i+1] left[i] left i au[i+1] au i+1 i 1 right[i+1] = right[i] + au[n-i-2] right[i+1] right i+1 i 1 right[i] + au[n-i-2] right[i] right i au[n-i-2] au n-i-2 n-i n i 2 p = min(n,k) p min(n,k) min n k for a in range(p+1):
    for b in range(p+1-a):
        d = deque(au)
        x = []
        y = 0
        for i in range(a):
            u = d.popleft()
            x.append(u)
            y += u
        for j in range(b):
            v = d.pop()
            x.append(v)
            y += v
        x.sort(reverse = True)
        for ue in range(k-a-b):
            if len(x) > 0 and x[-1] < 0:
                y -= x.pop()
            else:
                break
        ans = max(ans,y) a range(p+1) range p+1 p 1 for b in range(p+1-a):
        d = deque(au)
        x = []
        y = 0
        for i in range(a):
            u = d.popleft()
            x.append(u)
            y += u
        for j in range(b):
            v = d.pop()
            x.append(v)
            y += v
        x.sort(reverse = True)
        for ue in range(k-a-b):
            if len(x) > 0 and x[-1] < 0:
                y -= x.pop()
            else:
                break
        ans = max(ans,y) b range(p+1-a) range p+1-a p+1 p 1 a d = deque(au) d deque(au) deque au x = [] x [] y = 0 y 0 for i in range(a):
            u = d.popleft()
            x.append(u)
            y += u
         i range(a) range a u = d.popleft() u d.popleft() d.popleft d popleft x.append(u) x.append x append u y += u y u for j in range(b):
            v = d.pop()
            x.append(v)
            y += v
         j range(b) range b v = d.pop() v d.pop() d.pop d pop x.append(v) x.append x append v y += v y v x.sort(reverse = True) x.sort x sort reverse = True reverse True for ue in range(k-a-b):
            if len(x) > 0 and x[-1] < 0:
                y -= x.pop()
            else:
                break
         ue range(k-a-b) range k-a-b k-a k a b if len(x) > 0 and x[-1] < 0:
                y -= x.pop()
            else:
                break
         len(x) > 0 and x[-1] < 0 len(x) > 0 len(x) len x 0 x[-1] < 0 x[-1] x -1 0 y -= x.pop() y x.pop() x.pop x pop break ans = max(ans,y) ans max(ans,y) max ans y print(ans) print ans x = [] [] x y += v v y v = d.pop() d.pop() v y -= x.pop() x.pop() y ans = 0 0 ans d = deque(au) deque(au) d y = 0 0 y k = map(int,input().split()) map(int,input().split()) k right = [0 for i in range(n)] [0 for i in range(n)] right p = min(n,k) min(n,k) p ans = max(ans,y) max(ans,y) ans n,k = map(int,input().split()) map(int,input().split()) n y += u u y u = d.popleft() d.popleft() u au = list(map(int,input().split())) list(map(int,input().split())) au left = [0 for i in range(n)] [0 for i in range(n)] left
n,k = map(int,input().split())
from collections import deque
au = list(map(int,input().split()))
left = [0 for i in range(n)]
right = [0 for i in range(n)]
left[0] = au[0]
right[0] = au[-1]
ans = 0
for i in range(n-1):
    left[i+1] = left[i] + au[i+1]
    right[i+1] = right[i] + au[n-i-2]
p = min(n,k)
for a in range(p+1):
    for b in range(p+1-a):
        d = deque(au)
        x = []
        y = 0
        for i in range(a):
            u = d.popleft()
            x.append(u)
            y += u
        for j in range(b):
            v = d.pop()
            x.append(v)
            y += v
        x.sort(reverse = True)
        for ue in range(k-a-b):
            if len(x) > 0 and x[-1] < 0:
                y -= x.pop()
            else:
                break
        ans = max(ans,y)
print(ans)