N, K = map(int, input().split())
V = list(map(int, input().split()))
 
ans = 0
for a_plus_b in range(min(N, K) + 1): # a, bの全組み合わせで実施
    for a in range(a_plus_b + 1):
        b = a_plus_b - a
        gems = V[:a] # 左からa番目までを取得
        if b > 0:
            gems += V[-b:] # 右からb番目までを取得
        gems.sort()
        negative_gems = [g for g in gems if g < 0]
        ans = max(ans, sum(gems) - sum(negative_gems[:K - a_plus_b])) # K-(a+b)までネガティブのものを捨てられる 
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 ans = 0 ans 0 for a_plus_b in range(min(N, K) + 1): # a, bの全組み合わせで実施
    for a in range(a_plus_b + 1):
        b = a_plus_b - a
        gems = V[:a] # 左からa番目までを取得
        if b > 0:
            gems += V[-b:] # 右からb番目までを取得
        gems.sort()
        negative_gems = [g for g in gems if g < 0]
        ans = max(ans, sum(gems) - sum(negative_gems[:K - a_plus_b])) # K-(a+b)までネガティブのものを捨てられる  a_plus_b range(min(N, K) + 1) range min(N, K) + 1 min(N, K) min N K 1 for a in range(a_plus_b + 1):
        b = a_plus_b - a
        gems = V[:a] # 左からa番目までを取得
        if b > 0:
            gems += V[-b:] # 右からb番目までを取得
        gems.sort()
        negative_gems = [g for g in gems if g < 0]
        ans = max(ans, sum(gems) - sum(negative_gems[:K - a_plus_b])) # K-(a+b)までネガティブのものを捨てられる  a range(a_plus_b + 1) range a_plus_b + 1 a_plus_b 1 b = a_plus_b - a b a_plus_b - a a_plus_b a gems = V[:a] gems V[:a] V :a a if b > 0:
            gems += V[-b:] # 右からb番目までを取得
         b > 0 b 0 gems += V[-b:] gems V[-b:] V -b: -b b gems.sort() gems.sort gems sort g for g in gems if g < 0 for g in gems if g < 0 g gems g < 0 g 0 if g < 0 g negative_gems = [g for g in gems if g < 0] negative_gems [g for g in gems if g < 0] ans = max(ans, sum(gems) - sum(negative_gems[:K - a_plus_b])) ans max(ans, sum(gems) - sum(negative_gems[:K - a_plus_b])) max ans sum(gems) - sum(negative_gems[:K - a_plus_b]) sum(gems) sum gems sum(negative_gems[:K - a_plus_b]) sum negative_gems[:K - a_plus_b] negative_gems :K - a_plus_b K - a_plus_b K a_plus_b print(ans) print ans V = list(map(int, input().split())) list(map(int, input().split())) V ans = max(ans, sum(gems) - sum(negative_gems[:K - a_plus_b])) max(ans, sum(gems) - sum(negative_gems[:K - a_plus_b])) ans ans = 0 0 ans negative_gems = [g for g in gems if g < 0] [g for g in gems if g < 0] negative_gems N, K = map(int, input().split()) map(int, input().split()) N b = a_plus_b - a a_plus_b - a b gems = V[:a] V[:a] gems K = map(int, input().split()) map(int, input().split()) K gems += V[-b:] V[-b:] gems
N, K = map(int, input().split())
V = list(map(int, input().split()))
 
ans = 0
for a_plus_b in range(min(N, K) + 1): # a, bの全組み合わせで実施
    for a in range(a_plus_b + 1):
        b = a_plus_b - a
        gems = V[:a] # 左からa番目までを取得
        if b > 0:
            gems += V[-b:] # 右からb番目までを取得
        gems.sort()
        negative_gems = [g for g in gems if g < 0]
        ans = max(ans, sum(gems) - sum(negative_gems[:K - a_plus_b])) # K-(a+b)までネガティブのものを捨てられる 
print(ans)