N,K = list(map(int,input().split()))
V = list(map(int,input().split()))
out = 0
for left in range(0,K+1):
    for right in range(0,K-left+1):
        if left==0 and right==0:
            continue
        if left + right <= N:
            if right!=0:
                box = V[0:left] + V[N-right:N]
            else:
                box = V[0:left]
            S = sum(box)
            box.sort(reverse=True)
            t = -1
            Life = K-(left+right)
            while Life>0 and abs(t)<=len(box) and box[t]<0:
                S = S-box[t]
                Life += -1
                t += -1
            if S>out:
                out = S
print(max(out,0)) 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 out = 0 out 0 for left in range(0,K+1):
    for right in range(0,K-left+1):
        if left==0 and right==0:
            continue
        if left + right <= N:
            if right!=0:
                box = V[0:left] + V[N-right:N]
            else:
                box = V[0:left]
            S = sum(box)
            box.sort(reverse=True)
            t = -1
            Life = K-(left+right)
            while Life>0 and abs(t)<=len(box) and box[t]<0:
                S = S-box[t]
                Life += -1
                t += -1
            if S>out:
                out = S left range(0,K+1) range 0 K+1 K 1 for right in range(0,K-left+1):
        if left==0 and right==0:
            continue
        if left + right <= N:
            if right!=0:
                box = V[0:left] + V[N-right:N]
            else:
                box = V[0:left]
            S = sum(box)
            box.sort(reverse=True)
            t = -1
            Life = K-(left+right)
            while Life>0 and abs(t)<=len(box) and box[t]<0:
                S = S-box[t]
                Life += -1
                t += -1
            if S>out:
                out = S right range(0,K-left+1) range 0 K-left+1 K-left K left 1 if left==0 and right==0:
            continue
         left==0 and right==0 left==0 left 0 right==0 right 0 continue if left + right <= N:
            if right!=0:
                box = V[0:left] + V[N-right:N]
            else:
                box = V[0:left]
            S = sum(box)
            box.sort(reverse=True)
            t = -1
            Life = K-(left+right)
            while Life>0 and abs(t)<=len(box) and box[t]<0:
                S = S-box[t]
                Life += -1
                t += -1
            if S>out:
                out = S left + right <= N left + right left right N if right!=0:
                box = V[0:left] + V[N-right:N]
            else:
                box = V[0:left]
             right!=0 right 0 box = V[0:left] + V[N-right:N] box V[0:left] + V[N-right:N] V[0:left] V 0:left 0 left V[N-right:N] V N-right:N N-right N right N box = V[0:left] box V[0:left] V 0:left 0 left S = sum(box) S sum(box) sum box box.sort(reverse=True) box.sort box sort reverse=True reverse True t = -1 t -1 Life = K-(left+right) Life K-(left+right) K left+right left right while Life>0 and abs(t)<=len(box) and box[t]<0:
                S = S-box[t]
                Life += -1
                t += -1
             Life>0 and abs(t)<=len(box) and box[t]<0 Life>0 and abs(t)<=len(box) Life>0 Life 0 abs(t)<=len(box) abs(t) abs t len(box) len box box[t]<0 box[t] box t 0 S = S-box[t] S S-box[t] S box[t] box t Life += -1 Life -1 t += -1 t -1 if S>out:
                out = S S>out S out out = S out S print(max(out,0)) print max(out,0) max out 0 S = S-box[t] S-box[t] S out = S S out t = -1 -1 t K = list(map(int,input().split())) list(map(int,input().split())) K box = V[0:left] + V[N-right:N] V[0:left] + V[N-right:N] box N,K = list(map(int,input().split())) list(map(int,input().split())) N V = list(map(int,input().split())) list(map(int,input().split())) V S = sum(box) sum(box) S Life = K-(left+right) K-(left+right) Life t += -1 -1 t out = 0 0 out box = V[0:left] V[0:left] box Life += -1 -1 Life
N,K = list(map(int,input().split()))
V = list(map(int,input().split()))
out = 0
for left in range(0,K+1):
    for right in range(0,K-left+1):
        if left==0 and right==0:
            continue
        if left + right <= N:
            if right!=0:
                box = V[0:left] + V[N-right:N]
            else:
                box = V[0:left]
            S = sum(box)
            box.sort(reverse=True)
            t = -1
            Life = K-(left+right)
            while Life>0 and abs(t)<=len(box) and box[t]<0:
                S = S-box[t]
                Life += -1
                t += -1
            if S>out:
                out = S
print(max(out,0))