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

ans = 0
for x in range(N+1):
    for y in range(N+1):
        if x+y > N or x+y > K:
            break
        rest = min(K-x-y, x+y)
        As = Vs[:x] + Vs[N-y:]
        As.sort()
        score = sum(As)
        for i in range(rest):
            if As[i] < 0:
                score -= As[i]
        ans = max(ans, score)

print(ans) N, K = map(int, input().split()) N map(int, input().split()) map int input().split() ().split () input split K Vs = list(map(int, input().split())) Vs list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split ans = 0 ans 0 for x in range(N+1):
    for y in range(N+1):
        if x+y > N or x+y > K:
            break
        rest = min(K-x-y, x+y)
        As = Vs[:x] + Vs[N-y:]
        As.sort()
        score = sum(As)
        for i in range(rest):
            if As[i] < 0:
                score -= As[i]
        ans = max(ans, score) x range(N+1) range N+1 N 1 for y in range(N+1):
        if x+y > N or x+y > K:
            break
        rest = min(K-x-y, x+y)
        As = Vs[:x] + Vs[N-y:]
        As.sort()
        score = sum(As)
        for i in range(rest):
            if As[i] < 0:
                score -= As[i]
        ans = max(ans, score) y range(N+1) range N+1 N 1 if x+y > N or x+y > K:
            break
         x+y > N or x+y > K x+y > N x+y x y N x+y > K x+y x y K break rest = min(K-x-y, x+y) rest min(K-x-y, x+y) min K-x-y K-x K x y x+y x y As = Vs[:x] + Vs[N-y:] As Vs[:x] + Vs[N-y:] Vs[:x] Vs :x x Vs[N-y:] Vs N-y: N-y N y As.sort() As.sort As sort score = sum(As) score sum(As) sum As for i in range(rest):
            if As[i] < 0:
                score -= As[i]
         i range(rest) range rest if As[i] < 0:
                score -= As[i]
         As[i] < 0 As[i] As i 0 score -= As[i] score As[i] As i ans = max(ans, score) ans max(ans, score) max ans score print(ans) print ans rest = min(K-x-y, x+y) min(K-x-y, x+y) rest score -= As[i] As[i] score K = map(int, input().split()) map(int, input().split()) K ans = max(ans, score) max(ans, score) ans score = sum(As) sum(As) score ans = 0 0 ans Vs = list(map(int, input().split())) list(map(int, input().split())) Vs As = Vs[:x] + Vs[N-y:] Vs[:x] + Vs[N-y:] As N, K = map(int, input().split()) map(int, input().split()) N
N, K = map(int, input().split())
Vs = list(map(int, input().split()))

ans = 0
for x in range(N+1):
    for y in range(N+1):
        if x+y > N or x+y > K:
            break
        rest = min(K-x-y, x+y)
        As = Vs[:x] + Vs[N-y:]
        As.sort()
        score = sum(As)
        for i in range(rest):
            if As[i] < 0:
                score -= As[i]
        ans = max(ans, score)

print(ans)
