CodeEff/ECCO huggingface dataset:
# Original solution
def main():
    import sys
    import heapq
    from copy import deepcopy
    from collections import deque
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    _N, K = [int(x) for x in input().strip().split()]
    V = deque([int(x) for x in input().strip().split()])
    max_ans = sum([v for v in V if v > 0])

    def dfs(ans, q, V, k):
        # print(k, q, V)
        ans = max(ans, sum(q))
        if ans == max_ans:
            print(ans)
            exit()
        if k == K:
            return ans
        if q:
            t = heapq.heappop(q)
            if t < 0:
                V.appendleft(t)
                ans = max(ans, dfs(ans, q[:], V, k+1))
                V.popleft()
                V.append(t)
                ans = max(ans, dfs(ans, q, V, k+1))
                V.pop()
            heapq.heappush(q, t)
        if V:
            q_l = q[:]
            q_r = q[:]
            t = V.popleft()
            heapq.heappush(q_l, t)
            ans = max(ans, dfs(ans, q_l[:], V, k+1))
            V.appendleft(t)
            t = V.pop()
            heapq.heappush(q_r, t)
            ans = max(ans, dfs(ans, q_r[:], V, k+1))
            V.append(t)
            
        return ans
    print((dfs(-float('inf'), [], V, 0)))

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    import sys
    import heapq
    from copy import deepcopy
    from collections import deque
    sys.setrecursionlimit(10 ** 6)
    input = sys.stdin.readline
    N, K = [int(x) for x in input().strip().split()]
    V = [int(x) for x in input().strip().split()]
    ans = -float('inf')
    for l in range(min(N, K)+1):
        for r in range(min(N, K)-l+1):
            vt = sorted(V[:l] + V[N-r:])
            c = 0
            i = 0
            for i in range(len(vt)):
                if c == (K-l-r):
                    break
                if vt[i] < 0:
                    vt[i] = 0
                    c += 1
                else:
                    break
            ans = max(ans, sum(vt))

    print(ans)

if __name__ == '__main__':
    main()
# Original solution
from collections import deque
import heapq
import copy
n, k = list(map(int, input().split()))

v = deque(list(map(int, input().split())))
j = []
heapq.heapify(j)

def solve(hep, jue, c, end=k):
    if c==k:
        return sum(hep)
    result = [0]
    if len(jue)!=0:
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        heapq.heappush(x, y.pop())
        result.append(solve(x, y, c+1))
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        heapq.heappush(x, y.popleft())
        result.append(solve(x, y, c+1))

    if len(hep)!=0:
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        y.append(heapq.heappop(x))
        result.append(solve(x, y, c+1))
        x, y = copy.deepcopy(hep), copy.deepcopy(jue)
        y.appendleft(heapq.heappop(x))
        result.append(solve(x, y, c+1))

    return max(result)


print((solve(j, v, 0)))

# Optimized solution
import heapq
n, k = list(map(int, input().split()))
v = list(map(int, input().split()))

result = []
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1-i):
        x = v[:i]+v[n-j:]
        c = k - (i + j)
        x.sort()
        for t in range(min(len(x), c)):
            if x[0]<0:
                x.pop(0)
            else:
                break
        result.append(sum(x))
print((max(result)))
# Original solution
from copy import deepcopy
from collections import deque
from functools import partial, lru_cache
from heapq import heappush, heappop

inputs = open(0).readlines()
n, k = list(map(int, inputs[0].split()))
V = deque(list(map(int, inputs[1].split())))
W = []

def dfs(root, option, function):
    stack =[root]
    ans = 0
    while stack:
        current_node = stack.pop()
        ans = function(current_node, ans)
        for n in option(current_node):
            stack.append(n)
    return ans

def option(node, limit):
    i, j = node
    if i+j < limit:
        return ((i+1, j), (i, j+1))
    return tuple()

def function(node, ans, W, V, limit, memo):
    if node in memo:
        return max(ans, memo[node])
    i, j = node
    W_, V_ = list(map(deepcopy, (W, V)))
    for _ in range(i):
        if V_:
            heappush(W_, V_.pop())
    for _ in range(j):
        if V_:
            heappush(W_, V_.popleft())
    score = sum(W_)
    for _ in range(min(limit-i-j, i+j)):
        if W_ and W_[0] < 0:
            score -= heappop(W_)
    memo[node] = score
    return max(ans, memo[node])

ans = dfs((0, 0), partial(option, limit=min(n, k)), partial(function, W=W, V=V, limit=k, memo={}))
print(ans)

# Optimized solution
from collections import deque

inputs = open(0).readlines()
n, k = list(map(int, inputs[0].split()))
V = deque(list(map(int, inputs[1].split())))
def calc(ii, jj, kk):
    W = []
    for i in range(ii):
        W.append(V[i])
    for j in range(jj):
        W.append(V[-j-1])
    W.sort(reverse=True)
    for _ in range(kk):
        if W[-1] < 0:
            W.pop()
    return sum(W)

ans = 0
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1-i):
        for k_ in range(min(i+j, k+1-i-j)):
            ans = max(ans, calc(i, j, k_))
print(ans)
# Original solution
from collections import deque

inputs = open(0).readlines()
n, k = list(map(int, inputs[0].split()))
V = deque(list(map(int, inputs[1].split())))
def calc(ii, jj, kk):
    W = []
    for i in range(ii):
        W.append(V[i])
    for j in range(jj):
        W.append(V[-j-1])
    W.sort(reverse=True)
    for _ in range(kk):
        if W[-1] < 0:
            W.pop()
    return sum(W)

ans = 0
for i in range(min(n, k)+1):
    for j in range(min(n, k)+1-i):
        for k_ in range(min(i+j, k+1-i-j)):
            ans = max(ans, calc(i, j, k_))
print(ans)

# Optimized solution
n, k, *V = list(map(int, open(0).read().split()))
def calc(i, j, k):
    W = sorted(V[:i] + V[:-j-1:-1], reverse=True)
    for _ in range(k):
        if W[-1] < 0:
            W.pop()
    return sum(W)

ans = 0
r = min(n, k)+1
for i in range(r):
    for j in range(r-i):
        for k_ in range(min(i+j, k+1-i-j)):
            ans = max(ans, calc(i, j, k_))
print(ans)
# Original solution
import sys
input = sys.stdin.readline
from collections import deque

def main():
	n, k = list(map(int, input().strip().split()))
	v = deque(list(map(int, input().strip().split())))
	ans = 0
	for i in range(k+1):
		for j in range(k - i + 1):
			now = 0
			s = []
			if i + j > n:
				continue
			md = k - i - j
			for t in range(i):
				s.append(v[t])
				now += v[t]
			for t in range(j):
				s.append(v[n-1-t])
				now += v[n-1-t]
			s.sort()
			# for t in range(min(md, i+j)):
			# 	# print("t:{}, len:{}".format(t, len(s)))
			# 	if s[t] >= 0:
			# 		break
			# 	else:
			# 		s[t] = 0
			for t in range(md):
				if t >= len(s):
					break
				if s[t] >= 0:
					break
				now -= s[t]
			ans = max(now, ans)

	print(ans)


if __name__ == '__main__':
	main()


# Optimized solution
import sys
input = sys.stdin.readline

def main():
	n, k = list(map(int, input().strip().split()))
	v = list(map(int, input().strip().split()))
	ans = 0
	for a in range(k+1):
		for b in range(k-a+1):
			if a + b > n:
				continue
			t = sorted(v[:a] + v[n-b:])
			for i in range(k-a-b):
				if i < len(t) and t[i] < 0:
					t[i] = 0
			ans = max(ans, sum(t))
	print(ans)
if __name__ == '__main__':
	main()
# Original solution
N, K = list(map(int, input().split()))
V = list(map(int, input().split()))

ans = 0
s = [(K, V[:], [], False)]
while s:
    cnt, v, bag, flag = s.pop()
    ans = max(ans, sum(bag))
    if cnt > 0 and v and not flag:
        s.append((cnt-1, v[1:], bag + [v[0]], False))
        s.append((cnt-1, v[:-1], bag + [v[-1]], False))
    if cnt > 0 and bag:
        min_bag = min(bag)
        if min_bag < 0:
            bag.remove(min_bag)
            s.append((cnt-1, [], bag, True))


print(ans)


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

ans = 0
for l in range(K+1):
    for r in range(K-l+1):
        if l + r < N:
            bag = V[:l] + V[N-r:] + [0]
            rest_ope = K-l-r
        else:
            bag = V[:]
            rest_ope = K - N
        for _ in range(rest_ope):
            min_bag = min(bag)
            if min_bag < 0 and rest_ope > 0:
                bag.remove(min_bag)
                rest_ope -= 1
        else:
            ans = max(ans, sum(bag))

print(ans)
# Original solution
from collections import deque, _heapq
N, K = list(map(int, input().split()))
V = deque(list(map(int, input().split())))

class Money:
    def __init__(self):
        self.yen = 0
        self.red = []

    def value(self):
        return self.yen + sum(self.red)

    def add(self, yen):
        if yen >= 0:
            self.yen += yen
        else:
            self.red.append(yen)

    def remove(self, yen):
        if yen >= 0:
            self.yen -= yen
        else:
            self.red.remove(yen)

#mny = Money()
def get(cnt, mny, lstop, rstop):
    ans = mny.value()

    if cnt <= 0:
        return ans

    if len(V) > 0:

        if lstop == 0:
            w = V.popleft()
            mny.add(w)
            ans = max(ans, get(cnt-1, mny, lstop, rstop))
            mny.remove(w)
            V.appendleft(w)
        elif lstop > 0:
            lstop -= 1

        if rstop == 0:
            w = V.pop()
            mny.add(w)
            ans = max(ans, get(cnt-1, mny, -1, rstop))
            mny.remove(w)
            V.append(w)

    if len(mny.red) > 0:
        w = min(mny.red)
        mny.red.remove(w)

        V.appendleft(w)
        ans = max(ans, get(cnt-1, mny, -1, -1))
        V.popleft()

        mny.red.append(w)    

    return ans

print((get(K, Money(), 0, 0)))


# Optimized solution
from collections import deque, _heapq
N, K = list(map(int, input().split()))
V = deque(list(map(int, input().split())))

class Money:
    def __init__(self):
        self.yen = 0
        self.red = []

    def value(self):
        return self.yen + sum(self.red)

    def add(self, yen):
        if yen >= 0:
            self.yen += yen
        else:
            self.red.append(yen)

    def remove(self, yen):
        if yen >= 0:
            self.yen -= yen
        else:
            self.red.remove(yen)

#mny = Money()
def get(cnt, mny, lstop, rstop):
    ans = mny.value()

    if cnt <= 0:
        return ans

    if len(V) > 0:

        if not lstop:
            w = V.popleft()
            mny.add(w)
            ans = max(ans, get(cnt-1, mny, lstop, rstop))
            mny.remove(w)
            V.appendleft(w)

        if not rstop:
            w = V.pop()
            mny.add(w)
            ans = max(ans, get(cnt-1, mny, True, rstop))
            mny.remove(w)
            V.append(w)

    if len(mny.red) > 0:
        w = min(mny.red)
        mny.red.remove(w)

        V.appendleft(w)
        ans = max(ans, get(cnt-1, mny, True, True))
        V.popleft()

        mny.red.append(w)    

    return ans

print((get(K, Money(), 0, 0)))
# Original solution
from collections import deque
import copy

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

V = deque(list(map(int,input().split(" "))))

def search(N,K,V,score,a,b):
    if a+b < min(N,K):
        Vb = copy.copy(V)
        scoreA = copy.copy(score)
        scoreB=copy.copy(score)
        scoreA.append(V.popleft())
        A = search(N,K,V,scoreA,a+1,b)
        scoreB.append(Vb.pop())
        B = search(N,K,Vb,scoreB,a,b+1)
    score = sorted(score)
    counter = 0
    while(counter < K-a-b):
        if len(score)== 0:
            break;
        if score[0]<0:
            score.pop(0)
            counter +=1
        else:
            break;
    ans = sum(score)
    if a+b < min(N,K):
        return max(0,ans,A,B)
    else:
        return max(0,ans)

score = []
a = 0
b= 0
ans = search(N,K,V,score,a,b)
print(ans)

# Optimized solution
from collections import deque

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

V = deque(list(map(int,input().split(" "))))

def search(N,K,V,score):
    ans = 0
    for i in range(min(N,K)+1):
        for j in range(min(N,K)-i+1):
            score = []
            for a in range(i):#do operation A
                score.append(V[a])
            for b in range(j):#do operation B
                score.append(V[len(V)-b-1])
            score=sorted(score)
            counter = 0

            while(counter < K-i-j):#do operation C,D
                if len(score)== 0:
                    break;
                if score[0]<0:
                    score.pop(0)
                    counter +=1
                else:
                    break;   
            ans = max(ans,sum(score))

    return ans

score = []
ans = search(N,K,V,score)
print(ans)
# Original solution
#!/usr/bin/env python3
import sys
from collections import deque

def solve(N: int, K: int, V: "List[int]"):

    mani = []
    for ac in range(K+1):
        for bc in range(K+1):
            for cc in range(K+1):
                for dc in range(K+1):
                    if (ac+bc+cc+dc) == K:
                        mani.append([ac,bc,cc,dc])

    max_v = 0
    for m in mani:
        VV = deque(V)
        MV = []
        lenVV = len(VV)
        for i in range(min(m[0],lenVV)):
            MV.append(VV.popleft())

        lenVV = len(VV)
        for i in range(min(m[1],lenVV)):
            MV.append(VV.pop())

        MV.sort()
        MV = deque(MV)
        for i in range(m[2]+m[3]):
            if len(MV) > 0 and MV[0] < 0:
                MV.popleft()

        max_v = max(max_v,sum(MV))

    print(max_v)



            



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, V)

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import sys
from collections import deque

def solve(N: int, K: int, V: "List[int]"):

    mani = []
    for ac in range(K+1):
        for bc in range(K+1):
            for cc in range(K+1):
                if (ac+bc+cc) == K:
                    mani.append([ac,bc,cc])

    max_v = 0
    for m in mani:
        VV = deque(V)
        MV = []
        lenVV = len(VV)
        for i in range(min(m[0],lenVV)):
            MV.append(VV.popleft())

        lenVV = len(VV)
        for i in range(min(m[1],lenVV)):
            MV.append(VV.pop())

        MV.sort()
        MV = deque(MV)
        for i in range(m[2]):
            if len(MV) > 0 and MV[0] < 0:
                MV.popleft()

        max_v = max(max_v,sum(MV))

    print(max_v)



            



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    V = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, K, V)

if __name__ == '__main__':
    main()
# Original solution
import sys

read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs = sys.stdin.buffer.readlines


# rstrip().decode('utf-8')
# INF=float("inf")
#MOD=10**9+7
# sys.setrecursionlimit(2147483647)
# import math
#import numpy as np
# import operator
# import bisect
# from heapq import heapify,heappop,heappush
#from math import gcd
# from fractions import gcd
# from collections import deque
# from collections import defaultdict
# from collections import Counter
from itertools import accumulate
# from itertools import groupby
# from itertools import permutations
# from itertools import combinations
# from scipy.sparse import csr_matrix
# from scipy.sparse.csgraph import floyd_warshall
# from scipy.sparse.csgraph import csgraph_from_dense
# from scipy.sparse.csgraph import dijkstra
# map(int,input().split())


def main():
	n,k=list(map(int,input().split()))
	V=list(map(int,input().split()))
	V=[0]+V+[0]
	LL=list(accumulate(V))
	RR=list(accumulate(V[::-1]))[::-1]
	ans=0
	for l in range(n+1):
		for r in range(n-l+1):
			for x in range(l+r+1):
				if l+r+x<=k:
					xx=V[1:l+1]+V[n+1-r:n+1]
					xx.sort()
					xxx=list(accumulate(xx))
					xxx=[0]+xxx
					ans=max(ans,LL[l]+RR[n-r+1]-xxx[x])
	print(ans)

if __name__ == "__main__":
		main()


# Optimized solution
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(eval(input()))
def FI(): return int(eval(input()))
def MI(): return list(map(int,input().split()))
def MF(): return list(map(float,input().split()))
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n,k=MI()
	V=LI()

	ans=0

	for a in range(min(n+1,k+1)):
		for b in range(min(n-a+1,k-a+1)):
			S=[]
			S+=V[:a]
			S+=V[n-b:]
			S.sort()
			tmp=sum(S)
			cnt=max(0,k-a-b)
			for i in range(min(a+b,cnt)):

				if S[i]<0:
					tmp-=S[i]
				else:
					break
			ans=max(ans,tmp)
	print(ans)










if __name__ == "__main__":
	main()
# Original solution
import copy,heapq

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

ans=0
left=copy.copy(V)
for i in range(1,N):
    left[i]+=left[i-1]
right=copy.copy(V)
for i in range(1,N):
    right[-i-1]+=right[-i]
for i in range(0,N+1):
    for j in range(0,N-i+1):
        dispose=K-i-j
        if 0>dispose:
            continue
        test=0
        q=[]
        if i>0:
            test+=left[i-1]
            q+=V[:i]
        if j>0:
            test+=right[-j]
            q+=V[N-j:N]

        heapq.heapify(q)
        while dispose>0 and q:
            x=heapq.heappop(q)
            if 0>x:
                test-=x
                dispose-=1
            else:
                break
        ans=max(ans,test)

print(ans)


# Optimized solution
import random

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

if K==0:
    print((0))
    exit()

if 0:
    V=[random.randint(-10**7,10**7) for i in range(N)]

ans=-float("inf")

for i in range(N+1):
    for j in range(N-i+1):
        if i+j>K:
            continue
        tmp=[V[k] for k in range(i)]
        for k in range(j):
            tmp.append(V[-1-k])
        tmp.sort()
        rest=K-i-j
        minus=0
        base=sum(tmp)
        for k in range(min(rest,len(tmp))):
            if tmp[k]<0:
                minus+=tmp[k]
            else:
                break
        test=base-minus
        ans=max(ans,test)

print(ans)
# Original solution
import bisect

abcd = []
n, k = list(map(int, input().split())) 
v_list = list(map(int, input().split())) 

for a in range(0, k+1):
    for b in range(0, k+1-a):
        for c in range(0, k+1-a-b):
            d = k-a-b-c
            abcd.append([a,b,c,d])


ans = 0
for curr_abcd in abcd:
    a,b,c,d = curr_abcd
    cd = c+d
    if a + b >= n:
        have = sorted(v_list)
    else:
        have = sorted(v_list[0:a] + v_list[n-b:n]) 

    minus_cnt = bisect.bisect_right(have,0)
    have = have[ min(minus_cnt, cd) : ]
    curr_sum = sum(have) 
    ans = max(ans, curr_sum)

print(ans)

# Optimized solution
from bisect import bisect_left, bisect_right

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

ans = 0
for get_num in range(0,k+1):
    rem = k-get_num
    for l in range(0,get_num+1):
        r = get_num-l
        if l+r > n: continue
        ls = vl[:l]
        rs = vl[n-r:]
        curr_l = ls + rs
        curr_l.sort()
        minus_cnt = bisect_left(curr_l, 0)
        if minus_cnt <= rem:
            curr_ans = sum(curr_l[minus_cnt:])
            ans = max(curr_ans,ans)
        else:
            curr_ans = sum(curr_l[rem:])
            ans = max(curr_ans,ans)

print(ans)
# Original solution
from bisect import bisect_left, bisect_right

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

ans = 0
for get_num in range(0,k+1):
    rem = k-get_num
    for l in range(0,get_num+1):
        r = get_num-l
        if l+r > n: continue
        ls = vl[:l]
        rs = vl[n-r:]
        curr_l = ls + rs
        curr_l.sort()
        minus_cnt = bisect_left(curr_l, 0)
        if minus_cnt <= rem:
            curr_ans = sum(curr_l[minus_cnt:])
            ans = max(curr_ans,ans)
        else:
            curr_ans = sum(curr_l[rem:])
            ans = max(curr_ans,ans)

print(ans)

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

ans = 0
ab_max = min(n,k)
for l in range(ab_max+1):
    for r in range(ab_max+1):
        if l+r > k: continue
        if l > n-r: continue
        ls = vl[:l]
        rs = vl[n-r:]
        # print(ls,rs)
        vals = ls + rs
        rem = k-(l+r)
        # print(rem)
        vals.sort()
        curr_sum = sum(vals)
        for i in range(rem):
            if i >= len(vals): break
            if vals[i] < 0: curr_sum -= vals[i]
            else: break
        # print(curr_sum)
        ans = max(ans,curr_sum)

print(ans)
# Original solution
#import heapq
import copy

N,K=list(map(int,input().split()))
V=list(map(int,input().split()))
V.append(0)#右から取る時用

S=[0]*(N+1)#累積和
for i in range(N):
    S[i+1]=S[i]+V[i]

#左からi番目まで見たときに，持っている負の宝石
left=[[] for _ in range(N+1)]
for i in range(N):
    left[i+1]=copy.deepcopy(left[i])
    if V[i]<0:
        left[i+1].append(V[i])
        left[i+1].sort()
       
        
ans=0
#左からi個，右からj個とったときについて考える
for i in range(N+1):
    temp=S[i]
    rem=copy.deepcopy(left[i])
    #heapq.heapify(rem)
    for j in range(N+1-i):
        if i+j>K:
            break
        temp+=S[-1]-S[N-j]
        if V[N-j]<0:
            #heapq.heappush(rem,V[N-j])
            rem.append(V[N-j])
            rem.sort()
        ret=K-(i+j)#負の宝石を返却できる回数
        if ret>0:
            for k in range(min(ret,len(rem))):
                temp-=rem[k]
        ans=max(ans,temp)
        temp=S[i]
        
print(ans)




# Optimized solution
import sys
input = sys.stdin.readline

def I(): return int(eval(input()))
def MI(): return list(map(int, input().split()))
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    V=LI()
    
    ans=0
    import heapq
    
    #左からa個，右からb個とって，あまり分で負数を捨てる
    for a in range(K+1):
        for b in range(K+1):
            if a+b>min(K,N):
                break
            hq=[]
            heapq.heapify(hq)
            for i in range(a):
                heapq.heappush(hq,V[i])
            for j in range(b):
                heapq.heappush(hq,V[N-1-j])
                
            temp=0
            rem=K-(a+b)
            for i in range(a+b):
                v=heapq.heappop(hq)
                if v>=0:
                    temp+=v
                else:
                    if rem>0:
                        rem-=1
                    else:
                        temp+=v
                        
            ans=max(ans,temp)
            
    print(ans)
                
            

main()