n, k = map(int, input().split())
V = list(map(int, input().split()))

from collections import deque
V = deque(V)

import copy

ans = -10**18
for i in range(k+1):
    for j in range(k+1):
        if i+j > k:
            continue
        if i+j > n:
            continue
        V_ = copy.copy(V)
        temp = []
        for p in range(i):
            temp.append(V_.popleft())
        for q in range(j):
            temp.append(V_.pop())
        temp.sort()
        s = sum(temp)
        l = k-i-j
        for r in range(min(l, len(temp))):
            if temp[r] < 0:
                s -= temp[r]
        ans = max(ans, s)
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 from collections import deque V = deque(V) V deque(V) deque V import copy copy ans = -10**18 ans -10**18 -10 18 for i in range(k+1):
    for j in range(k+1):
        if i+j > k:
            continue
        if i+j > n:
            continue
        V_ = copy.copy(V)
        temp = []
        for p in range(i):
            temp.append(V_.popleft())
        for q in range(j):
            temp.append(V_.pop())
        temp.sort()
        s = sum(temp)
        l = k-i-j
        for r in range(min(l, len(temp))):
            if temp[r] < 0:
                s -= temp[r]
        ans = max(ans, s) i range(k+1) range k+1 k 1 for j in range(k+1):
        if i+j > k:
            continue
        if i+j > n:
            continue
        V_ = copy.copy(V)
        temp = []
        for p in range(i):
            temp.append(V_.popleft())
        for q in range(j):
            temp.append(V_.pop())
        temp.sort()
        s = sum(temp)
        l = k-i-j
        for r in range(min(l, len(temp))):
            if temp[r] < 0:
                s -= temp[r]
        ans = max(ans, s) j range(k+1) range k+1 k 1 if i+j > k:
            continue
         i+j > k i+j i j k continue if i+j > n:
            continue
         i+j > n i+j i j n continue V_ = copy.copy(V) V_ copy.copy(V) copy.copy copy copy V temp = [] temp [] for p in range(i):
            temp.append(V_.popleft())
         p range(i) range i temp.append(V_.popleft()) temp.append temp append V_.popleft() V_.popleft V_ popleft for q in range(j):
            temp.append(V_.pop())
         q range(j) range j temp.append(V_.pop()) temp.append temp append V_.pop() V_.pop V_ pop temp.sort() temp.sort temp sort s = sum(temp) s sum(temp) sum temp l = k-i-j l k-i-j k-i k i j for r in range(min(l, len(temp))):
            if temp[r] < 0:
                s -= temp[r]
         r range(min(l, len(temp))) range min(l, len(temp)) min l len(temp) len temp if temp[r] < 0:
                s -= temp[r]
         temp[r] < 0 temp[r] temp r 0 s -= temp[r] s temp[r] temp r ans = max(ans, s) ans max(ans, s) max ans s print(ans) print ans s = sum(temp) sum(temp) s l = k-i-j k-i-j l n, k = map(int, input().split()) map(int, input().split()) n temp = [] [] temp V = deque(V) deque(V) V V_ = copy.copy(V) copy.copy(V) V_ V = list(map(int, input().split())) list(map(int, input().split())) V s -= temp[r] temp[r] s k = map(int, input().split()) map(int, input().split()) k ans = max(ans, s) max(ans, s) ans ans = -10**18 -10**18 ans
n, k = map(int, input().split())
V = list(map(int, input().split()))

from collections import deque
V = deque(V)

import copy

ans = -10**18
for i in range(k+1):
    for j in range(k+1):
        if i+j > k:
            continue
        if i+j > n:
            continue
        V_ = copy.copy(V)
        temp = []
        for p in range(i):
            temp.append(V_.popleft())
        for q in range(j):
            temp.append(V_.pop())
        temp.sort()
        s = sum(temp)
        l = k-i-j
        for r in range(min(l, len(temp))):
            if temp[r] < 0:
                s -= temp[r]
        ans = max(ans, s)
print(ans)
