N,K = map(int,input().split())
V = list(map(int,input().split()))

import heapq
ans = 0
for a in range(min(N,K)+1):
    for b in range(min(N,K)-a+1):
        A = V[:a] + V[N-b:]
        heapq.heapify(A)
        for c in range(min(a+b, K-a-b)):
            small = heapq.heappop(A)
            if small > 0:
                heapq.heappush(A,small)
                break
        ans = max(ans, sum(A))
print(ans) 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 import heapq heapq ans = 0 ans 0 for a in range(min(N,K)+1):
    for b in range(min(N,K)-a+1):
        A = V[:a] + V[N-b:]
        heapq.heapify(A)
        for c in range(min(a+b, K-a-b)):
            small = heapq.heappop(A)
            if small > 0:
                heapq.heappush(A,small)
                break
        ans = max(ans, sum(A)) a range(min(N,K)+1) range min(N,K)+1 min(N,K) min N K 1 for b in range(min(N,K)-a+1):
        A = V[:a] + V[N-b:]
        heapq.heapify(A)
        for c in range(min(a+b, K-a-b)):
            small = heapq.heappop(A)
            if small > 0:
                heapq.heappush(A,small)
                break
        ans = max(ans, sum(A)) b range(min(N,K)-a+1) range min(N,K)-a+1 min(N,K)-a min(N,K) min N K a 1 A = V[:a] + V[N-b:] A V[:a] + V[N-b:] V[:a] V :a a V[N-b:] V N-b: N-b N b heapq.heapify(A) heapq.heapify heapq heapify A for c in range(min(a+b, K-a-b)):
            small = heapq.heappop(A)
            if small > 0:
                heapq.heappush(A,small)
                break
         c range(min(a+b, K-a-b)) range min(a+b, K-a-b) min a+b a b K-a-b K-a K a b small = heapq.heappop(A) small heapq.heappop(A) heapq.heappop heapq heappop A if small > 0:
                heapq.heappush(A,small)
                break
         small > 0 small 0 heapq.heappush(A,small) heapq.heappush heapq heappush A small break ans = max(ans, sum(A)) ans max(ans, sum(A)) max ans sum(A) sum A print(ans) print ans N,K = map(int,input().split()) map(int,input().split()) N ans = max(ans, sum(A)) max(ans, sum(A)) ans K = map(int,input().split()) map(int,input().split()) K V = list(map(int,input().split())) list(map(int,input().split())) V ans = 0 0 ans A = V[:a] + V[N-b:] V[:a] + V[N-b:] A small = heapq.heappop(A) heapq.heappop(A) small
N,K = map(int,input().split())
V = list(map(int,input().split()))

import heapq
ans = 0
for a in range(min(N,K)+1):
    for b in range(min(N,K)-a+1):
        A = V[:a] + V[N-b:]
        heapq.heapify(A)
        for c in range(min(a+b, K-a-b)):
            small = heapq.heappop(A)
            if small > 0:
                heapq.heappush(A,small)
                break
        ans = max(ans, sum(A))
print(ans)
