from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
a = inpl()
res = 0
for i in range(k+1):
    pick = i; back = k-i
    for j in range(pick+1):
        l = j; r = pick-j
        q = deque(a)
        # print(l,r)
        now = []
        while q and l > 0:
            now.append(q.popleft())
            l -= 1
        while q and r > 0:
            now.append(q.pop())
            r -= 1
        now.sort(); ln = len(now)
        ans = sum(now)
        res = max(res, ans)
        for i in range(back):
            if i >= ln: continue
            ans -= now[i]
            res = max(res, ans)
print(res) from collections import Counter,defaultdict,deque from heapq import heappop,heappush,heapify import sys,bisect,math,itertools,fractions sys bisect math itertools fractions sys.setrecursionlimit(10**8) sys.setrecursionlimit sys setrecursionlimit 10**8 10 8 mod = 10**9+7 mod 10**9+7 10**9 10 9 7 INF = float('inf') INF float('inf') float 'inf' def inp(): return int(sys.stdin.readline()) inp def inpl(): return list(map(int, sys.stdin.readline().split())) inpl n,k = inpl() n inpl() inpl k a = inpl() a inpl() inpl res = 0 res 0 for i in range(k+1):
    pick = i; back = k-i
    for j in range(pick+1):
        l = j; r = pick-j
        q = deque(a)
        # print(l,r)
        now = []
        while q and l > 0:
            now.append(q.popleft())
            l -= 1
        while q and r > 0:
            now.append(q.pop())
            r -= 1
        now.sort(); ln = len(now)
        ans = sum(now)
        res = max(res, ans)
        for i in range(back):
            if i >= ln: continue
            ans -= now[i]
            res = max(res, ans) i range(k+1) range k+1 k 1 pick = i pick i back = k-i back k-i k i for j in range(pick+1):
        l = j; r = pick-j
        q = deque(a)
        # print(l,r)
        now = []
        while q and l > 0:
            now.append(q.popleft())
            l -= 1
        while q and r > 0:
            now.append(q.pop())
            r -= 1
        now.sort(); ln = len(now)
        ans = sum(now)
        res = max(res, ans)
        for i in range(back):
            if i >= ln: continue
            ans -= now[i]
            res = max(res, ans) j range(pick+1) range pick+1 pick 1 l = j l j r = pick-j r pick-j pick j q = deque(a) q deque(a) deque a now = [] now [] while q and l > 0:
            now.append(q.popleft())
            l -= 1
         q and l > 0 q l > 0 l 0 now.append(q.popleft()) now.append now append q.popleft() q.popleft q popleft l -= 1 l 1 while q and r > 0:
            now.append(q.pop())
            r -= 1
         q and r > 0 q r > 0 r 0 now.append(q.pop()) now.append now append q.pop() q.pop q pop r -= 1 r 1 now.sort() now.sort now sort ln = len(now) ln len(now) len now ans = sum(now) ans sum(now) sum now res = max(res, ans) res max(res, ans) max res ans for i in range(back):
            if i >= ln: continue
            ans -= now[i]
            res = max(res, ans) i range(back) range back if i >= ln: continue
             i >= ln i ln ans -= now[i] ans now[i] now i res = max(res, ans) res max(res, ans) max res ans print(res) print res res = 0 0 res def inp(): return int(sys.stdin.readline()) def inp(): return int(sys.stdin.readline()) inp a = inpl() inpl() a l = j j l def inpl(): return list(map(int, sys.stdin.readline().split())) def inpl(): return list(map(int, sys.stdin.readline().split())) inpl k = inpl() inpl() k back = k-i k-i back r = pick-j pick-j r ans -= now[i] now[i] ans res = max(res, ans) max(res, ans) res res = max(res, ans) max(res, ans) res now = [] [] now q = deque(a) deque(a) q ans = sum(now) sum(now) ans r -= 1 1 r mod = 10**9+7 10**9+7 mod pick = i i pick INF = float('inf') float('inf') INF n,k = inpl() inpl() n l -= 1 1 l ln = len(now) len(now) ln
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,k = inpl()
a = inpl()
res = 0
for i in range(k+1):
    pick = i; back = k-i
    for j in range(pick+1):
        l = j; r = pick-j
        q = deque(a)
        # print(l,r)
        now = []
        while q and l > 0:
            now.append(q.popleft())
            l -= 1
        while q and r > 0:
            now.append(q.pop())
            r -= 1
        now.sort(); ln = len(now)
        ans = sum(now)
        res = max(res, ans)
        for i in range(back):
            if i >= ln: continue
            ans -= now[i]
            res = max(res, ans)
print(res)