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

R = min(N,K)
point = 0
max_point = 0
hand = []

for i in range(R+1):
    for a in range(i+1):
        if i==a:
            hand = V[:a]
        else:
            hand = V[:a]+V[-(i-a):]
        negahand = [k for k in hand if k < 0]
        negahand.sort()
        if K-i > len(negahand):
            trash = -sum(negahand)
        else:
            trash = -sum(negahand[:K-i])
        point = sum(hand) + trash
        max_point = max(max_point,point)

print(max_point) N, K = list(map(int, input().split())) N list(map(int, input().split())) list 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 R = min(N,K) R min(N,K) min N K point = 0 point 0 max_point = 0 max_point 0 hand = [] hand [] for i in range(R+1):
    for a in range(i+1):
        if i==a:
            hand = V[:a]
        else:
            hand = V[:a]+V[-(i-a):]
        negahand = [k for k in hand if k < 0]
        negahand.sort()
        if K-i > len(negahand):
            trash = -sum(negahand)
        else:
            trash = -sum(negahand[:K-i])
        point = sum(hand) + trash
        max_point = max(max_point,point) i range(R+1) range R+1 R 1 for a in range(i+1):
        if i==a:
            hand = V[:a]
        else:
            hand = V[:a]+V[-(i-a):]
        negahand = [k for k in hand if k < 0]
        negahand.sort()
        if K-i > len(negahand):
            trash = -sum(negahand)
        else:
            trash = -sum(negahand[:K-i])
        point = sum(hand) + trash
        max_point = max(max_point,point) a range(i+1) range i+1 i 1 if i==a:
            hand = V[:a]
        else:
            hand = V[:a]+V[-(i-a):]
         i==a i a hand = V[:a] hand V[:a] V :a a hand = V[:a]+V[-(i-a):] hand V[:a]+V[-(i-a):] V[:a] V :a a V[-(i-a):] V -(i-a): -(i-a) i-a i a k for k in hand if k < 0 for k in hand if k < 0 k hand k < 0 k 0 if k < 0 k negahand = [k for k in hand if k < 0] negahand [k for k in hand if k < 0] negahand.sort() negahand.sort negahand sort if K-i > len(negahand):
            trash = -sum(negahand)
        else:
            trash = -sum(negahand[:K-i])
         K-i > len(negahand) K-i K i len(negahand) len negahand trash = -sum(negahand) trash -sum(negahand) sum(negahand) sum negahand trash = -sum(negahand[:K-i]) trash -sum(negahand[:K-i]) sum(negahand[:K-i]) sum negahand[:K-i] negahand :K-i K-i K i point = sum(hand) + trash point sum(hand) + trash sum(hand) sum hand trash max_point = max(max_point,point) max_point max(max_point,point) max max_point point print(max_point) print max_point negahand = [k for k in hand if k < 0] [k for k in hand if k < 0] negahand point = 0 0 point max_point = max(max_point,point) max(max_point,point) max_point V = list(map(int, input().split())) list(map(int, input().split())) V point = sum(hand) + trash sum(hand) + trash point trash = -sum(negahand[:K-i]) -sum(negahand[:K-i]) trash N, K = list(map(int, input().split())) list(map(int, input().split())) N max_point = 0 0 max_point K = list(map(int, input().split())) list(map(int, input().split())) K hand = V[:a] V[:a] hand hand = V[:a]+V[-(i-a):] V[:a]+V[-(i-a):] hand R = min(N,K) min(N,K) R trash = -sum(negahand) -sum(negahand) trash hand = [] [] hand
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))

R = min(N,K)
point = 0
max_point = 0
hand = []

for i in range(R+1):
    for a in range(i+1):
        if i==a:
            hand = V[:a]
        else:
            hand = V[:a]+V[-(i-a):]
        negahand = [k for k in hand if k < 0]
        negahand.sort()
        if K-i > len(negahand):
            trash = -sum(negahand)
        else:
            trash = -sum(negahand[:K-i])
        point = sum(hand) + trash
        max_point = max(max_point,point)

print(max_point)