CodeEff/ECCO huggingface dataset:
# Original solution
from itertools import chain, islice
 
R = lambda: list(map(int, input().split()))
n, k = R()
v = list(R())
a = sorted((x, i) for i, x in enumerate(v) if x < 0)
ans = max(sum(chain(v[:i - j], v[n - j:])) -
          sum(islice((x for x, m in a if m < i - j or m >= n - j), k - i))
          for i in range(1, min(n, k) + 1) for j in range(i))
print(ans)


# Optimized solution
R = lambda: list(map(int, input().split()))
n, k = R()
v = list(R())
a = sorted((x, i) for i, x in enumerate(v) if x < 0)
ans = max(sum(v[:i - j] + v[n - j:]) -
          sum([x for x, m in a if m < i - j or m >= n - j][:k - i])
          for i in range(1, min(n, k) + 1) for j in range(i))
print(ans)
# Original solution
R = lambda: list(map(int, input().split()))
n, k = R()
v = list(R())
a = sorted((x, i) for i, x in enumerate(v) if x < 0)
ans = max(sum(v[:i - j] + v[n - j:]) -
          sum([x for x, m in a if m < i - j or m >= n - j][:k - i])
          for i in range(1, min(n, k) + 1) for j in range(i))
print(ans)


# Optimized solution
R = lambda: list(map(int, input().split()))
n, k = R()
v = list(R())
ans = max(sum(v[:i - j] + v[n - j:]) -
          sum(sorted(x for x in v[:i - j] + v[n - j:] if x < 0)[: k - i])
          for i in range(1, min(n, k) + 1) for j in range(i))
print(ans)
# Original solution
N,K=list(map(int,input().split()))
V=list(map(int,input().split()))
r=min(N,K)
ans=0
for a in range(r+1):
    for b in range(r-a+1):
        tmp,minus=0,[]
        for i in range(a):
            t=V[i]
            tmp+=t
            if t<0:
                minus.append(t)
        for j in range(b):
            t=V[N-1-j]
            tmp+=t
            if t<0:
                minus.append(t)
        tmp-=sum(sorted(minus)[:K-(a+b)])
        ans=max(ans,tmp)
print(ans)


# Optimized solution
N,K=list(map(int,input().split()))
V=list(map(int,input().split()))
r,ans=min(N,K),0
for a in range(r+1):
  for b in range(r-a+1):
    tmp,minus=0,[]
    for i in range(a):
      tmp+=V[i]
      if V[i]<0:
        minus.append(V[i])
    for j in range(b):
      tmp+=V[N-j-1]
      if V[N-j-1]<0:
        minus.append(V[N-j-1])
    tmp-=sum(sorted(minus)[:K-(a+b)])
    ans=max(ans,tmp)
print(ans)
# Original solution
from heapq import heappush, heappop, heapify

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

# N jewels in dequeue D
# at most K operations
# 1 <= N <= 50
# 1 <= K <= 100
# -10000000 <= Vi <= 10000000

# Operation A, B: Remove left or right
# Operation C, D: Add to left or right

S = 0
for take in range(K + 1):
    for takeL in range(take + 1):
        for takeR in range(take - takeL + 1):
            hand = []
            for i in range(takeL):
                if i >= len(V):
                    break
                heappush(hand, V[i])
            for i in range(takeR):
                if N - i - 1 < takeL:
                    break
                heappush(hand, V[N- i - 1])
            S = max(sum(hand), S)
            for _ in range(K - take):
                if not hand or hand[0] >= 0:
                    break
                heappop(hand)
                S = max(sum(hand), S)
print(S)



# Optimized solution
from heapq import heappush, heappop, heapify

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

# N jewels in dequeue D
# at most K operations
# 1 <= N <= 50
# 1 <= K <= 100
# -10000000 <= Vi <= 10000000

# Operation A, B: Remove left or right
# Operation C, D: Add to left or right

S = 0
for take in range(min(N, K) + 1):
    for takeL in range(take + 1):
        for takeR in range(take - takeL + 1):
            hand = []
            for i in range(takeL):
                heappush(hand, V[i])
            for i in range(takeR):
                if N - i - 1 < takeL:
                    break
                heappush(hand, V[N- i - 1])
            S = max(sum(hand), S)
            for _ in range(K - take):
                if not hand or hand[0] >= 0:
                    break
                heappop(hand)
                S = max(sum(hand), S)
print(S)
# Original solution
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N,K = list(map(int,input().split()))
V = [int(i) for i in input().split()]
#
if N == 1:
    print((max(0,V[0])))
    exit()

ans = 0
for i in range(K): # 戻す数
    for j in range(K-i+1):
        if j <= N-(K-i-j):
            ans_list = V[:j]+V[N-(K-i-j):]
            ans_list.sort()
            tmp = sum(ans_list)
            for k in range(min(len(ans_list),i)):
                if ans_list[k] < 0:
                    tmp -= ans_list[k]
            ans = max(ans,tmp)
        else:
            pass

print((max(ans,0)))


# Optimized solution
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N,K = list(map(int,input().split()))
V = [int(i) for i in input().split()]
#
# if N == 1:
#     print(max(0,V[0]))
#     exit()

ans = 0
for i in range(K): # 戻す数
    for j in range(K-i+1):
        if j <= N-(K-i-j):
            ans_list = V[:j]+V[N-(K-i-j):]
            ans_list.sort()
            tmp = sum(ans_list)
            for k in range(min(len(ans_list),i)):
                if ans_list[k] < 0:
                    tmp -= ans_list[k]
            ans = max(ans,tmp)
        else:
            pass

print((max(ans,0)))
# Original solution
# -*- coding: utf-8 -*-
"""
Created on Sun May 26 20:56:05 2019

@author: Yamazaki Kenichi
"""
import heapq

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

def a(K):
    if K > N:
        return N
    else:
        return K

ans = 0
for i in range(K):
    for j in range(a(K-i)+1):
        tmp = 0
        minus = [0]
        for k in range(a(K-i)):
            tmp += V[k-j]
            heapq.heappush(minus,V[k-j])
#            print(tmp,minus)
        for k2 in range(i):
            if minus[0] < 0:
                tmp += (-heapq.heappop(minus))
            else:
                break
#        print(ans,tmp,i,j,k)
        ans = max(ans,tmp)
    
print(ans)

# Optimized solution
# -*- coding: utf-8 -*-
"""
Created on Wed May 29 22:59:58 2019

@author: Yamazaki Kenichi
"""

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

ans = 0
for pickup_n in range(min(K, N)+1):
    for start in range(pickup_n + 1):
        tmp = [0]
        for i in range(pickup_n):
            tmp.append(V[i - start])
        tmp.sort()
        for i in range(K - pickup_n):
            if tmp[i] < 0:
                tmp[i] = 0
            else:
                break
        ans = max(ans,sum(tmp))
print(ans)
# Original solution
import heapq

n,k=list(map(int,input().split()))
v=list(map(int,input().split()))
s=-10**7-1

if n>k:
    for l in range(k//2+1):
        for i in range(k+1-l):
            d=v[:i]
            d.extend(v[(n-k+l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(l):
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res
else:
    for l in range(n+1):
        for i in range(n-l+1):
            d=v[:i]
            d.extend(v[(l+i):])
            heap=heapq.heapify(d)
            res=sum(d)
            for j in range(k-(n-l)):
                if not d:
                    break
                t=heapq.heappop(d)
                if t<0:
                    res-=t
                else:
                    break
            if s<res:
                s=res

        
if s<0:
    print((0))
else:
    print(s)
        


# Optimized solution
import heapq

res=0
n,k=list(map(int,input().split()))
v=list(map(int,input().split()))
r=min(n,k)
for a in range(r+1):#操作Aの回数
    for b in range(r-a+1):#Bの回数
        d=v[:a]
        d.extend(v[n-b:])
        s=sum(d)
        heapq.heapify(d)

        l=k-(a+b) #捨てる回数print(d)
        for _ in range(l):
            if not d:
              break
            t=heapq.heappop(d)
            if t<0:
               s-=t
            else:
                break
        if s>res:
            res=s
print(res)
# Original solution
import heapq
from collections import deque
from copy import deepcopy

n,k = list(map(int,input().split()))
U = deque(list(map(int,input().split())))

Max = -10**9

for a in range(min(n,k)+1):
  for b in range(min(n,k)+1-a):
    
    V = deepcopy(U)
    Heap = []
    heapq.heapify(Heap)
    
    if a >= 1:
      for i in range(a):
        heapq.heappush(Heap,V.pop())
        
    if b >= 1:  
      for i in range(b):
        heapq.heappush(Heap,V.popleft())
        
    if k-a-b >= 1:
      for i in range(k-a-b):
        
        if len(Heap) >= 1:
          Min = heapq.heappop(Heap)
                 
          if Min >= 0:
            heapq.heappush(Heap,Min)
            break

    Max = max(Max,sum(Heap))
    
print(Max)

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

cum = [0]
rcum = [0]

for i in range(N):
    cum.append(cum[-1]+V[i])
    rcum.append(rcum[-1]+V[-1-i])

ans = 0

for i in range(N+1):
    for j in range(N+1):

        if i+j > min(N,K):
            continue

        value = cum[i]+rcum[j]
        neg = []

        for ii in range(i):
            if V[ii] < 0:
                neg.append(V[ii])

        for jj in range(j):
            if V[-1-jj] < 0:
                neg.append(V[-1-jj])

        neg.sort()

        value -= sum(neg[:min(K-i-j,len(neg))])

        ans = max(ans,value)

print(ans)
# Original solution
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))

ans = 0
for l_pop in range(K + 1):
    for r_pop in range(K + 1):
        X = []
        if (l_pop + r_pop > K) or (l_pop + r_pop > N):
            continue
        else:
            X.extend(V[:l_pop])
            X.extend(V[::-1][:r_pop])

        X.sort()
        tmp = sum(X)
        for k in range(K - l_pop - r_pop):
            if k > len(X) - 1:
                break
            else:
                if X[k] < 0:
                    tmp -= X[k]

        ans = max(ans, tmp)

print(ans)


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

# 最終的に「持っているもの」の価値の合計を高めたい
# Dから取り出すことをpop、Dに詰めることをenqueueとする
ans = 0
for pop_cnt in range(K + 1):
    enqueue_cnt = K - pop_cnt

    if pop_cnt > N:
        continue

    for l in range(pop_cnt + 1):
        holding = []

        r = pop_cnt - l
        holding += V[:l]
        holding += V[N - r:]

        holding.sort()
        tmp_ans = sum(holding)

        for e in range(enqueue_cnt):
            if e >= len(holding):
                break

            if holding[e] < 0:
                tmp_ans += -holding[e]

        ans = max(ans, tmp_ans)

print(ans)
# Original solution
# ABC128D - equeue
# exhaustive search
def main():
    N, K = tuple(map(int, input().rstrip().split()))
    V = tuple(map(int, input().rstrip().split()))
    lim = min(N, K)
    ans = set()
    for l in range(N + 1):
        for r in range(N + 1):
            if l + r > lim:
                break
            # picked jewels (l from left, r from right)
            cur = sorted(V[:l] + V[-r:]) if r != 0 else sorted(V[:l])
            neg = sum(i < 0 for i in cur)
            rest = K - (l + r)
            # return unworthy ones as much as possible
            if neg > rest:
                ans |= {sum(cur[rest:])}
            else:
                ans |= {sum(i for i in cur if i >= 0)}
    print((max(ans)))


if __name__ == "__main__":
    main()

# Optimized solution
# D - equeue
def main():
    N, K, *V = list(map(int, open(0).read().split()))
    lim = min(N, K)
    available_choices = set()

    for l in range(lim + 1):
        for r in range(lim + 1):
            if l + r > lim:
                break

            choice = V[:l] + V[-r:] if r else V[:l]
            cnt_negatives = sum(i < 0 for i in choice)
            cnt_rest = K - (l + r)

            if cnt_negatives > cnt_rest:
                choice.sort()
                available_choices.add(sum(choice[cnt_rest:]))
            else:
                available_choices.add(sum(i for i in choice if i > 0))

    print((max(available_choices)))


if __name__ == "__main__":
    main()
# Original solution
import sys
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]

ans = 0
for i in range(K + 1):
    for j in range(K + 1 - i):
        for k in range(K + 1 - i - j):
            tmp = list()
            tmp.extend(V[:min(i, N)])
            tmp.extend(V[max(i, N - j):N])
            tmp.sort(reverse=True)
            for _ in range(k):
                if len(tmp) > 0 and tmp[-1] < 0:
                    tmp.pop()
            ans = max(ans, sum(tmp))

print(ans)




# Optimized solution
import sys
input = sys.stdin.readline
N, K = [int(x) for x in input().split()]
V = [int(x) for x in input().split()]

ans = 0
for i in range(K + 1):
    for j in range(K + 1 - i):
        k = K - i - j
        tmp = list()
        tmp.extend(V[:min(i, N)])
        tmp.extend(V[max(i, N - j):N])
        tmp.sort(reverse=True)
        for _ in range(k):
            if len(tmp) > 0 and tmp[-1] < 0:
                tmp.pop()
        ans = max(ans, sum(tmp))

print(ans)
# Original solution
import heapq, copy
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = -10 ** 10
for a in range(min(n, k) + 1):
    have = []
    for i in range(a):
        have.append(v[i])

    o_have = copy.deepcopy(have)

    for b in range(min(n, k) - a + 1):
        for i in range(b):
            have.append(v[n-i-1])

        heapq.heapify(have)
        # print(1, have)
        for c in range(k - a - b):
            if len(have) <= 0:
                break
            item = heapq.heappop(have)
            # print(c, item, have)
            if item >= 0:
                have.append(item)
                break
        ans = max(ans, sum(have))
        # print(2, have, ans, a, b)
        have = copy.deepcopy(o_have)

print(ans)


# Optimized solution
import heapq, copy
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))
ans = -10 ** 10
for a in range(min(n, k) + 1):
    for b in range(min(n, k) - a + 1):
        have = []
        
        for i in range(a):
            have.append(v[i])
        for i in range(b):
            have.append(v[n-i-1])

        heapq.heapify(have)
        
        for c in range(k - a - b):
            if len(have) <= 0:
                break
            item = heapq.heappop(have)
            if item >= 0:
                have.append(item)
                break
        ans = max(ans, sum(have))

print(ans)
# Original solution
# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
N, K = list(map(int, input().split()))
D = [int(x) for x in input().split()]
# S = input()

ans = 0
for l in range(N + 1):
    if l > K:
        break

    for r in range(N - l + 1):
        if l + r > K:
            break

        l_list = sorted(D[0 : l])
        r_list = sorted(D[N - r : N])

        for discard_l in range(K - (l + r) + 1):
            if l + r + discard_l > K:
                break
                
            for discard_r in range(K - (l + r + discard_l) + 1):
                if l + r + discard_l + discard_r > K:
                    break
                    
                value = sum(l_list[discard_l:])
                value += sum(r_list[discard_r:])

                ans = max(ans, value)
        
print(ans)


# Optimized solution
# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
N, K = list(map(int, input().split()))
D = [int(x) for x in input().split()]
# S = input()

ans = 0
for l in range(N + 1):
    if l > K:
        break

    for r in range(N - l + 1):
        if l + r > K:
            break

        value_list = D[0 : l] + D[N - r : N]
        value_list.sort()
        
        for i in range(K - (l + r) + 1):
            ans = max(ans, sum(value_list[i:]))
        
print(ans)
# Original solution
# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
N, K = list(map(int, input().split()))
D = [int(x) for x in input().split()]
# S = input()

ans = 0
for l in range(N + 1):
    if l > K:
        break

    for r in range(N - l + 1):
        if l + r > K:
            break

        l_list = sorted(D[0 : l])
        r_list = sorted(D[N - r : N])

        for discard_l in range(K - (l + r) + 1):
            for discard_r in range(K - (l + r + discard_l) + 1):
                value = sum(l_list[discard_l:])
                value += sum(r_list[discard_r:])

                ans = max(ans, value)
        
print(ans)


# Optimized solution
# coding: utf-8

import sys
input = sys.stdin.readline

# N = int(input())
N, K = list(map(int, input().split()))
D = [int(x) for x in input().split()]
# S = input()

ans = 0
for l in range(N + 1):
    if l > K:
        break

    for r in range(N - l + 1):
        if l + r > K:
            break

        value_list = D[0 : l] + D[N - r : N]
        value_list.sort()
        
        for i in range(K - (l + r) + 1):
            ans = max(ans, sum(value_list[i:]))
        
print(ans)
# Original solution
N,K = list(map(int,input().split()))
V = [0] + list(map(int,input().split())) + [0]
m = min(N,K)

A = []
ans = 0

#左からi個、右からj個除いた時の宝石の価値のmax

for i in range(m+1):
    if i == 0:
        pass
    else:
        A.append(V[i])
    B = []
    for j in range(m-i+1):
        if j == 0:
            pass
        else:
            B.append(V[N-j+1])
        C = A+B
        C.sort()
        a = sum(C)
        for k in range(len(C)):
            if C[k] < 0 and k < K-(i+j):
                a -= C[k]
        ans = max(ans,a)

print(ans)

# Optimized solution
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,K = MI()
V = LI()

ans = 0
for i in range(K+1):  # 操作回数
    for j in range(N+1):  # 左から
        for k in range(N+1):  # 右から
            if j + k > min(N,i):
                break
            l = i-j-k
            if l > j+k:
                continue
            A = [V[m] for m in range(j)] + [V[N-1-m] for m in range(k)]
            A.sort(reverse=True)
            ans = max(ans,sum(A[m] for m in range(j+k-l)))
print(ans)
# Original solution
import heapq

n, k = list(map(int, input().split()))
lst = list(map(int, input().split()))

def heap_push(my_lst, a):
    heapq.heappush(my_lst, a)
    return my_lst


def dfs(k, lst, my_lst):
    if k == 0:
        return max(sum(my_lst), 0)
    
    if len(my_lst) == 0:
        a = dfs(k-1, lst[1:], heap_push(my_lst[:], lst[0]))
        b = dfs(k-1, lst[:-1], heap_push(my_lst[:], lst[-1]))
        return max(a, b)
                
    if len(lst) == 0:
        return dfs(k-1, lst + heapq.nsmallest(1,my_lst), my_lst[1:])
                
    else:
        a = dfs(k-1, lst[1:], heap_push(my_lst[:], lst[0]))
        b = dfs(k-1, lst[:-1], heap_push(my_lst[:], lst[-1]))
        
        c = dfs(k-1, lst + heapq.nsmallest(1,my_lst), my_lst[1:])
        d = dfs(k-1, heapq.nsmallest(1,my_lst) + lst, my_lst[1:])
        return max(a,b,c,d)
    
my_lst = []
heapq.heapify(my_lst)
print((dfs(k, lst, [])))

# Optimized solution
n, k = list(map(int, input().split()))
lst = list(map(int, input().split()))

res = 0
max_num = min(n, k)
for i in range(max_num+1):
    for j in range(max_num+1 - i):
        my_lst = []
        my_lst += lst[:i]
        if j != 0:
            my_lst += lst[-j:]
        
        s = sum(my_lst)
        sorted_my_lst = sorted(my_lst)
        #print('my_lst :', my_lst)
        for l in range(k- i - j):
            if len(my_lst) > l:
                if sorted_my_lst[l] < 0:
                    s -= sorted_my_lst[l]
        res = max(res, s)

print(res)
# Original solution
from collections import deque 

n, k = list(map(int, input().split()))
vs_ = deque(list(map(int, input().split())))

max_v = 0

import copy

for a in range(k+1):
  for b in range(k+1-a):
    for c in range(k+1-a-b):
      vs = copy.copy(vs_)
      us = []
      for x in range(a):
        if vs:
          us.append(vs.popleft())
        else:
          break
      for y in range(b):
        if vs:
          us.append(vs.pop())
        else:
          break
      #print(us)
      us.sort(reverse=True)
      for z in range(c):
        if len(us) and us[-1]<0:
          us.pop()
        else:
          break
      if sum(us) >= max_v:
        max_v = sum(us)

print(max_v)

      
  

# Optimized solution
n, k = list(map(int, input().split()))
V = list(map(int, input().split()))

from collections import deque
V = deque(V)

import copy

ans = -10**18
for i in range(k+1):
    for j in range(k+1):
        if i+j > k:
            continue
        if i+j > n:
            continue
        V_ = copy.copy(V)
        temp = []
        for p in range(i):
            temp.append(V_.popleft())
        for q in range(j):
            temp.append(V_.pop())
        temp.sort()
        s = sum(temp)
        l = k-i-j
        for r in range(min(l, len(temp))):
            if temp[r] < 0:
                s -= temp[r]
        ans = max(ans, s)
print(ans)
# Original solution
import bisect

N, K = list(map(int, input().split()))
V = [int(i) for i in input().split()]

ans = 0
for a in range(min(N, K)+1):
    for b in range(min(N, K)-a+1):
        score = 0
        D = sorted(V[:a]+V[N-b:])
        score = sum(D[min(K-(a+b), bisect.bisect_left(D, 0)):])
        # print(score)
        ans = max(ans, score)

print(ans)


# Optimized solution
import bisect

N, K = list(map(int, input().split()))
V = [int(i) for i in input().split()]

ans = -10**20
for l in range(min(K+1, N+1)):
    for r in range(min(K-l+1, N-l+1)):
        P = V[:l]+V[N-r:]
        P.sort()
        z = bisect.bisect_left(P, 0)

        if z <= K-l-r:
            ans = max(ans, sum(P[z:]))
        else:
            ans = max(ans, sum(P[K-l-r:]))

print(ans)
# Original solution
# -*- coding: utf-8 -*-


def main():
    n, k = list(map(int, input().split()))
    v = list(map(int, input().split()))
    reverse_v = v[::-1]
    ans = 0

    for left in range(k + 1):
        for right in range(k - left + 1):
            if left + right > n:
                continue

            remain = k - (left + right)
            merged_v = sorted(v[:left] + reverse_v[:right])
            merged_v_len = len(merged_v)
            minus = 0

            for i in range(min(remain, merged_v_len)):
                if merged_v[i] < 0:
                    minus += merged_v[i]

            ans = max(ans, sum(merged_v) - minus)

    print(ans)


if __name__ == '__main__':
    main()


# Optimized solution
# -*- coding: utf-8 -*-


def main():
    n, k = list(map(int, input().split()))
    v = list(map(int, input().split()))
    reverse_v = v[::-1]
    ans = 0

    # See:
    # https://www.youtube.com/watch?v=m-Nov1EvGoc
    for left in range(k + 1):
        for right in range(k - left + 1):
            if left + right > n:
                continue

            remain = k - (left + right)
            merged_v = sorted(v[:left] + reverse_v[:right])
            merged_v_len = len(merged_v)
            minus = 0

            for i in range(min(remain, merged_v_len)):
                if merged_v[i] < 0:
                    minus += merged_v[i]

            ans = max(ans, sum(merged_v) - minus)

    print(ans)


if __name__ == '__main__':
    main()