N,K = map(int,input().split())
V = list(map(int,input().split()))
import heapq 
m = min(N,K)
M = 0
for i in range(m+1):
    for j in range(m-i+1):
        v1 = V[:i]
        v3 = V[N-j:]
        v = v1+v3
        heapq.heapify(v)
        h = K - len(v)
        while v  and h >0:
            q = heapq.heappop(v)
            h-=1
            if q > 0:
                heapq.heappush(v,q)
                break
        tmp = sum(v)
        # print(v,v3)
        M = max(M,tmp)
print(M) 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 m = min(N,K) m min(N,K) min N K M = 0 M 0 for i in range(m+1):
    for j in range(m-i+1):
        v1 = V[:i]
        v3 = V[N-j:]
        v = v1+v3
        heapq.heapify(v)
        h = K - len(v)
        while v  and h >0:
            q = heapq.heappop(v)
            h-=1
            if q > 0:
                heapq.heappush(v,q)
                break
        tmp = sum(v)
        # print(v,v3)
        M = max(M,tmp) i range(m+1) range m+1 m 1 for j in range(m-i+1):
        v1 = V[:i]
        v3 = V[N-j:]
        v = v1+v3
        heapq.heapify(v)
        h = K - len(v)
        while v  and h >0:
            q = heapq.heappop(v)
            h-=1
            if q > 0:
                heapq.heappush(v,q)
                break
        tmp = sum(v)
        # print(v,v3)
        M = max(M,tmp) j range(m-i+1) range m-i+1 m-i m i 1 v1 = V[:i] v1 V[:i] V :i i v3 = V[N-j:] v3 V[N-j:] V N-j: N-j N j v = v1+v3 v v1+v3 v1 v3 heapq.heapify(v) heapq.heapify heapq heapify v h = K - len(v) h K - len(v) K len(v) len v while v  and h >0:
            q = heapq.heappop(v)
            h-=1
            if q > 0:
                heapq.heappush(v,q)
                break
         v  and h >0 v h >0 h 0 q = heapq.heappop(v) q heapq.heappop(v) heapq.heappop heapq heappop v h-=1 h 1 if q > 0:
                heapq.heappush(v,q)
                break
         q > 0 q 0 heapq.heappush(v,q) heapq.heappush heapq heappush v q break tmp = sum(v) tmp sum(v) sum v M = max(M,tmp) M max(M,tmp) max M tmp print(M) print M K = map(int,input().split()) map(int,input().split()) K V = list(map(int,input().split())) list(map(int,input().split())) V h-=1 1 h v = v1+v3 v1+v3 v q = heapq.heappop(v) heapq.heappop(v) q M = max(M,tmp) max(M,tmp) M tmp = sum(v) sum(v) tmp v1 = V[:i] V[:i] v1 N,K = map(int,input().split()) map(int,input().split()) N m = min(N,K) min(N,K) m M = 0 0 M v3 = V[N-j:] V[N-j:] v3 h = K - len(v) K - len(v) h
N,K = map(int,input().split())
V = list(map(int,input().split()))
import heapq 
m = min(N,K)
M = 0
for i in range(m+1):
    for j in range(m-i+1):
        v1 = V[:i]
        v3 = V[N-j:]
        v = v1+v3
        heapq.heapify(v)
        h = K - len(v)
        while v  and h >0:
            q = heapq.heappop(v)
            h-=1
            if q > 0:
                heapq.heappush(v,q)
                break
        tmp = sum(v)
        # print(v,v3)
        M = max(M,tmp)
print(M)