from collections import deque
n, k = map(int, input().split())
v = list(map(int, input().split()))
d = deque(v)

t = min(n, k)
score = 0
for a in range(t+1):
    for b in range(t-a+1):
        tmp_d = d.copy()
        jems = []
        for i in range(a):
            jems.append(tmp_d.pop())
        for i in range(b):
            jems.append(tmp_d.popleft())
        jems.sort()
        for i in range(min(len(jems), k-b-a)):
            if jems[i] < 0:
                jems[i] = 0
            else:
                break
        tmp_score = sum(jems)
        if tmp_score > score:
            score = tmp_score
print(score) from collections import deque 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 d = deque(v) d deque(v) deque v t = min(n, k) t min(n, k) min n k score = 0 score 0 for a in range(t+1):
    for b in range(t-a+1):
        tmp_d = d.copy()
        jems = []
        for i in range(a):
            jems.append(tmp_d.pop())
        for i in range(b):
            jems.append(tmp_d.popleft())
        jems.sort()
        for i in range(min(len(jems), k-b-a)):
            if jems[i] < 0:
                jems[i] = 0
            else:
                break
        tmp_score = sum(jems)
        if tmp_score > score:
            score = tmp_score a range(t+1) range t+1 t 1 for b in range(t-a+1):
        tmp_d = d.copy()
        jems = []
        for i in range(a):
            jems.append(tmp_d.pop())
        for i in range(b):
            jems.append(tmp_d.popleft())
        jems.sort()
        for i in range(min(len(jems), k-b-a)):
            if jems[i] < 0:
                jems[i] = 0
            else:
                break
        tmp_score = sum(jems)
        if tmp_score > score:
            score = tmp_score b range(t-a+1) range t-a+1 t-a t a 1 tmp_d = d.copy() tmp_d d.copy() d.copy d copy jems = [] jems [] for i in range(a):
            jems.append(tmp_d.pop())
         i range(a) range a jems.append(tmp_d.pop()) jems.append jems append tmp_d.pop() tmp_d.pop tmp_d pop for i in range(b):
            jems.append(tmp_d.popleft())
         i range(b) range b jems.append(tmp_d.popleft()) jems.append jems append tmp_d.popleft() tmp_d.popleft tmp_d popleft jems.sort() jems.sort jems sort for i in range(min(len(jems), k-b-a)):
            if jems[i] < 0:
                jems[i] = 0
            else:
                break
         i range(min(len(jems), k-b-a)) range min(len(jems), k-b-a) min len(jems) len jems k-b-a k-b k b a if jems[i] < 0:
                jems[i] = 0
            else:
                break
         jems[i] < 0 jems[i] jems i 0 jems[i] = 0 jems[i] jems i 0 break tmp_score = sum(jems) tmp_score sum(jems) sum jems if tmp_score > score:
            score = tmp_score tmp_score > score tmp_score score score = tmp_score score tmp_score print(score) print score score = 0 0 score v = list(map(int, input().split())) list(map(int, input().split())) v tmp_score = sum(jems) sum(jems) tmp_score d = deque(v) deque(v) d k = map(int, input().split()) map(int, input().split()) k score = tmp_score tmp_score score n, k = map(int, input().split()) map(int, input().split()) n tmp_d = d.copy() d.copy() tmp_d t = min(n, k) min(n, k) t jems = [] [] jems
from collections import deque
n, k = map(int, input().split())
v = list(map(int, input().split()))
d = deque(v)

t = min(n, k)
score = 0
for a in range(t+1):
    for b in range(t-a+1):
        tmp_d = d.copy()
        jems = []
        for i in range(a):
            jems.append(tmp_d.pop())
        for i in range(b):
            jems.append(tmp_d.popleft())
        jems.sort()
        for i in range(min(len(jems), k-b-a)):
            if jems[i] < 0:
                jems[i] = 0
            else:
                break
        tmp_score = sum(jems)
        if tmp_score > score:
            score = tmp_score
print(score)
