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

#a:左からとる b:右からとる K-a-b:捨てる
score=0
torikata=[]
for d in range(101):
    for a in range(101):
        for b in range(101):
            if d+a+b<=K and a+b<=N:
                torikata.append((a,b,d))

for i in range(len(torikata)):
    A,B,D=torikata[i][0],torikata[i][1],torikata[i][2]
    H=[]
    for i in range(A):
        H.append(V[i])
    for i in range(B):
        H.append(V[-(i+1)])
    heapq.heapify(H)
    for i in range(min(D,A+B)):
        heapq.heappop(H)
    score=max(score,sum(H))

print(score) import heapq heapq 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 score=0 score 0 torikata=[] torikata [] for d in range(101):
    for a in range(101):
        for b in range(101):
            if d+a+b<=K and a+b<=N:
                torikata.append((a,b,d)) d range(101) range 101 for a in range(101):
        for b in range(101):
            if d+a+b<=K and a+b<=N:
                torikata.append((a,b,d)) a range(101) range 101 for b in range(101):
            if d+a+b<=K and a+b<=N:
                torikata.append((a,b,d)) b range(101) range 101 if d+a+b<=K and a+b<=N:
                torikata.append((a,b,d)) d+a+b<=K and a+b<=N d+a+b<=K d+a+b d+a d a b K a+b<=N a+b a b N torikata.append((a,b,d)) torikata.append torikata append (a,b,d) a b d for i in range(len(torikata)):
    A,B,D=torikata[i][0],torikata[i][1],torikata[i][2]
    H=[]
    for i in range(A):
        H.append(V[i])
    for i in range(B):
        H.append(V[-(i+1)])
    heapq.heapify(H)
    for i in range(min(D,A+B)):
        heapq.heappop(H)
    score=max(score,sum(H)) i range(len(torikata)) range len(torikata) len torikata A,B,D=torikata[i][0],torikata[i][1],torikata[i][2] A torikata[i][0] [i] torikata i 0 B torikata[i][1] [i] torikata i 1 D torikata[i][2] [i] torikata i 2 H=[] H [] for i in range(A):
        H.append(V[i])
     i range(A) range A H.append(V[i]) H.append H append V[i] V i for i in range(B):
        H.append(V[-(i+1)])
     i range(B) range B H.append(V[-(i+1)]) H.append H append V[-(i+1)] V -(i+1) i+1 i 1 heapq.heapify(H) heapq.heapify heapq heapify H for i in range(min(D,A+B)):
        heapq.heappop(H)
     i range(min(D,A+B)) range min(D,A+B) min D A+B A B heapq.heappop(H) heapq.heappop heapq heappop H score=max(score,sum(H)) score max(score,sum(H)) max score sum(H) sum H print(score) print score B,D=torikata[i][0],torikata[i][1],torikata[i][2] torikata[i][1] B D=torikata[i][0],torikata[i][1],torikata[i][2] torikata[i][2] D H=[] [] H A,B,D=torikata[i][0],torikata[i][1],torikata[i][2] torikata[i][0] A score=max(score,sum(H)) max(score,sum(H)) score V=list(map(int,input().split())) list(map(int,input().split())) V score=0 0 score K=map(int,input().split()) map(int,input().split()) K N,K=map(int,input().split()) map(int,input().split()) N torikata=[] [] torikata
import heapq
N,K=map(int,input().split())
V=list(map(int,input().split()))

#a:左からとる b:右からとる K-a-b:捨てる
score=0
torikata=[]
for d in range(101):
    for a in range(101):
        for b in range(101):
            if d+a+b<=K and a+b<=N:
                torikata.append((a,b,d))

for i in range(len(torikata)):
    A,B,D=torikata[i][0],torikata[i][1],torikata[i][2]
    H=[]
    for i in range(A):
        H.append(V[i])
    for i in range(B):
        H.append(V[-(i+1)])
    heapq.heapify(H)
    for i in range(min(D,A+B)):
        heapq.heappop(H)
    score=max(score,sum(H))

print(score)