N, K = map(int, input().split())
V = list(map(int, input().split()))
result = 0
for a in range(N + 1):
    for b in range(N + 1):
        if a + b > K or a + b > N:
            break
        out = V[:a] + V[N-b:]
        out.sort()
        sum_val = sum(out)
        for i in range(min(a + b, K - a - b)):
            if out[i] >= 0:
                break
            sum_val -= out[i]
        result = max(result, sum_val);
print(result) 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 result = 0 result 0 for a in range(N + 1):
    for b in range(N + 1):
        if a + b > K or a + b > N:
            break
        out = V[:a] + V[N-b:]
        out.sort()
        sum_val = sum(out)
        for i in range(min(a + b, K - a - b)):
            if out[i] >= 0:
                break
            sum_val -= out[i]
        result = max(result, sum_val); a range(N + 1) range N + 1 N 1 for b in range(N + 1):
        if a + b > K or a + b > N:
            break
        out = V[:a] + V[N-b:]
        out.sort()
        sum_val = sum(out)
        for i in range(min(a + b, K - a - b)):
            if out[i] >= 0:
                break
            sum_val -= out[i]
        result = max(result, sum_val); b range(N + 1) range N + 1 N 1 if a + b > K or a + b > N:
            break
         a + b > K or a + b > N a + b > K a + b a b K a + b > N a + b a b N break out = V[:a] + V[N-b:] out V[:a] + V[N-b:] V[:a] V :a a V[N-b:] V N-b: N-b N b out.sort() out.sort out sort sum_val = sum(out) sum_val sum(out) sum out for i in range(min(a + b, K - a - b)):
            if out[i] >= 0:
                break
            sum_val -= out[i]
         i range(min(a + b, K - a - b)) range min(a + b, K - a - b) min a + b a b K - a - b K - a K a b if out[i] >= 0:
                break
             out[i] >= 0 out[i] out i 0 break sum_val -= out[i] sum_val out[i] out i result = max(result, sum_val) result max(result, sum_val) max result sum_val print(result) print result K = map(int, input().split()) map(int, input().split()) K result = 0 0 result sum_val -= out[i] out[i] sum_val N, K = map(int, input().split()) map(int, input().split()) N sum_val = sum(out) sum(out) sum_val out = V[:a] + V[N-b:] V[:a] + V[N-b:] out V = list(map(int, input().split())) list(map(int, input().split())) V result = max(result, sum_val) max(result, sum_val) result
N, K = map(int, input().split())
V = list(map(int, input().split()))
result = 0
for a in range(N + 1):
    for b in range(N + 1):
        if a + b > K or a + b > N:
            break
        out = V[:a] + V[N-b:]
        out.sort()
        sum_val = sum(out)
        for i in range(min(a + b, K - a - b)):
            if out[i] >= 0:
                break
            sum_val -= out[i]
        result = max(result, sum_val);
print(result)