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

max_value = 0
for num_take in range(min(N, K)+1):
    max_put = min(K - num_take, max(num_take-1, 0))
    for i in range(num_take+1):
        deque = list(V)
        gems = []
        left_right = [0 for _ in range(i)] + [1 for _ in range(num_take-i)]
        for which in left_right:
            if len(deque) > 0:
                if which == 0:
                    gems.append(deque.pop(0))
                else:
                    gems.append(deque.pop(-1))
        gems.sort()

        value = max([sum(gems[num_put:]) for num_put in range(max_put+1)])
        max_value = max(max_value, value)
        
print(max_value) 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 max_value = 0 max_value 0 for num_take in range(min(N, K)+1):
    max_put = min(K - num_take, max(num_take-1, 0))
    for i in range(num_take+1):
        deque = list(V)
        gems = []
        left_right = [0 for _ in range(i)] + [1 for _ in range(num_take-i)]
        for which in left_right:
            if len(deque) > 0:
                if which == 0:
                    gems.append(deque.pop(0))
                else:
                    gems.append(deque.pop(-1))
        gems.sort()

        value = max([sum(gems[num_put:]) for num_put in range(max_put+1)])
        max_value = max(max_value, value)
         num_take range(min(N, K)+1) range min(N, K)+1 min(N, K) min N K 1 max_put = min(K - num_take, max(num_take-1, 0)) max_put min(K - num_take, max(num_take-1, 0)) min K - num_take K num_take max(num_take-1, 0) max num_take-1 num_take 1 0 for i in range(num_take+1):
        deque = list(V)
        gems = []
        left_right = [0 for _ in range(i)] + [1 for _ in range(num_take-i)]
        for which in left_right:
            if len(deque) > 0:
                if which == 0:
                    gems.append(deque.pop(0))
                else:
                    gems.append(deque.pop(-1))
        gems.sort()

        value = max([sum(gems[num_put:]) for num_put in range(max_put+1)])
        max_value = max(max_value, value)
         i range(num_take+1) range num_take+1 num_take 1 deque = list(V) deque list(V) list V gems = [] gems [] 0 for _ in range(i) for _ in range(i) _ range(i) range i for _ in range(i) 0 left_right = [0 for _ in range(i)] + [1 for _ in range(num_take-i)] left_right [0 for _ in range(i)] + [1 for _ in range(num_take-i)] [0 for _ in range(i)] [1 for _ in range(num_take-i)] for which in left_right:
            if len(deque) > 0:
                if which == 0:
                    gems.append(deque.pop(0))
                else:
                    gems.append(deque.pop(-1))
         which left_right if len(deque) > 0:
                if which == 0:
                    gems.append(deque.pop(0))
                else:
                    gems.append(deque.pop(-1))
         len(deque) > 0 len(deque) len deque 0 if which == 0:
                    gems.append(deque.pop(0))
                else:
                    gems.append(deque.pop(-1))
         which == 0 which 0 gems.append(deque.pop(0)) gems.append gems append deque.pop(0) deque.pop deque pop 0 gems.append(deque.pop(-1)) gems.append gems append deque.pop(-1) deque.pop deque pop -1 gems.sort() gems.sort gems sort sum(gems[num_put:]) for num_put in range(max_put+1) for num_put in range(max_put+1) num_put range(max_put+1) range max_put+1 max_put 1 for num_put in range(max_put+1) sum(gems[num_put:]) sum gems[num_put:] gems num_put: num_put value = max([sum(gems[num_put:]) for num_put in range(max_put+1)]) value max([sum(gems[num_put:]) for num_put in range(max_put+1)]) max [sum(gems[num_put:]) for num_put in range(max_put+1)] max_value = max(max_value, value) max_value max(max_value, value) max max_value value print(max_value) print max_value max_put = min(K - num_take, max(num_take-1, 0)) min(K - num_take, max(num_take-1, 0)) max_put left_right = [0 for _ in range(i)] + [1 for _ in range(num_take-i)] [0 for _ in range(i)] + [1 for _ in range(num_take-i)] left_right deque = list(V) list(V) deque max_value = 0 0 max_value N, K = map(int, input().split()) map(int, input().split()) N V = list(map(int, input().split())) list(map(int, input().split())) V value = max([sum(gems[num_put:]) for num_put in range(max_put+1)]) max([sum(gems[num_put:]) for num_put in range(max_put+1)]) value max_value = max(max_value, value) max(max_value, value) max_value K = map(int, input().split()) map(int, input().split()) K gems = [] [] gems
N, K = map(int, input().split())
V = list(map(int, input().split()))

max_value = 0
for num_take in range(min(N, K)+1):
    max_put = min(K - num_take, max(num_take-1, 0))
    for i in range(num_take+1):
        deque = list(V)
        gems = []
        left_right = [0 for _ in range(i)] + [1 for _ in range(num_take-i)]
        for which in left_right:
            if len(deque) > 0:
                if which == 0:
                    gems.append(deque.pop(0))
                else:
                    gems.append(deque.pop(-1))
        gems.sort()

        value = max([sum(gems[num_put:]) for num_put in range(max_put+1)])
        max_value = max(max_value, value)
        
print(max_value)