N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for pick in range(min(K+1, N+1)):
    for right in range(pick+1):
        left = pick - right
        pick_list = V[:right] + V[N-left:]

        pick_list.sort()
        tmp_ans = sum(pick_list)
        rem = min(K - pick, len(pick_list))
        for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans)
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 ans = 0 ans 0 for pick in range(min(K+1, N+1)):
    for right in range(pick+1):
        left = pick - right
        pick_list = V[:right] + V[N-left:]

        pick_list.sort()
        tmp_ans = sum(pick_list)
        rem = min(K - pick, len(pick_list))
        for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans) pick range(min(K+1, N+1)) range min(K+1, N+1) min K+1 K 1 N+1 N 1 for right in range(pick+1):
        left = pick - right
        pick_list = V[:right] + V[N-left:]

        pick_list.sort()
        tmp_ans = sum(pick_list)
        rem = min(K - pick, len(pick_list))
        for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans) right range(pick+1) range pick+1 pick 1 left = pick - right left pick - right pick right pick_list = V[:right] + V[N-left:] pick_list V[:right] + V[N-left:] V[:right] V :right right V[N-left:] V N-left: N-left N left pick_list.sort() pick_list.sort pick_list sort tmp_ans = sum(pick_list) tmp_ans sum(pick_list) sum pick_list rem = min(K - pick, len(pick_list)) rem min(K - pick, len(pick_list)) min K - pick K pick len(pick_list) len pick_list for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
         i range(rem) range rem if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
         pick_list[i] < 0 pick_list[i] pick_list i 0 tmp_ans -= pick_list[i] tmp_ans pick_list[i] pick_list i break ans = max(tmp_ans, ans) ans max(tmp_ans, ans) max tmp_ans ans print(ans) print ans rem = min(K - pick, len(pick_list)) min(K - pick, len(pick_list)) rem ans = max(tmp_ans, ans) max(tmp_ans, ans) ans ans = 0 0 ans left = pick - right pick - right left pick_list = V[:right] + V[N-left:] V[:right] + V[N-left:] pick_list V = list(map(int, input().split())) list(map(int, input().split())) V tmp_ans -= pick_list[i] pick_list[i] tmp_ans N, K = map(int, input().split()) map(int, input().split()) N tmp_ans = sum(pick_list) sum(pick_list) tmp_ans K = map(int, input().split()) map(int, input().split()) K
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for pick in range(min(K+1, N+1)):
    for right in range(pick+1):
        left = pick - right
        pick_list = V[:right] + V[N-left:]

        pick_list.sort()
        tmp_ans = sum(pick_list)
        rem = min(K - pick, len(pick_list))
        for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans)
print(ans)