Alice and Bob are playing yet another card game. This time the rules are the following. There are n cards lying in a row in front of them. The i-th card has value a_i. 

First, Alice chooses a non-empty consecutive segment of cards [l; r] (l ≤ r). After that Bob removes a single card j from that segment (l ≤ j ≤ r). The score of the game is the total value of the remaining cards on the segment (a_l + a_{l + 1} + ... + a_{j - 1} + a_{j + 1} + ... + a_{r - 1} + a_r). In particular, if Alice chooses a segment with just one element, then the score after Bob removes the only card is 0.

Alice wants to make the score as big as possible. Bob takes such a card that the score is as small as possible.

What segment should Alice choose so that the score is maximum possible? Output the maximum score.

Input

The first line contains a single integer n (1 ≤ n ≤ 10^5) — the number of cards.

The second line contains n integers a_1, a_2, ..., a_n (-30 ≤ a_i ≤ 30) — the values on the cards.

Output

Print a single integer — the final score of the game.

Examples

Input


5
5 -2 10 -1 4


Output


6


Input


8
5 2 5 3 -30 -30 6 9


Output


10


Input


3
-10 6 -15


Output


0

Note

In the first example Alice chooses a segment [1;5] — the entire row of cards. Bob removes card 3 with the value 10 from the segment. Thus, the final score is 5 + (-2) + (-1) + 4 = 6.

In the second example Alice chooses a segment [1;4], so that Bob removes either card 1 or 3 with the value 5, making the answer 5 + 2 + 3 = 10.

In the third example Alice can choose any of the segments of length 1: [1;1], [2;2] or [3;3]. Bob removes the only card, so the score is 0. If Alice chooses some other segment then the answer will be less than 0.
from sys import stdin, stdout

#5
#5 -2 10 -4 1
#5 -2 -1 1
#3 -2 -1 2
#11
#3 0 1 -2 999 -5 -1 0 3 2 2
#9999 -1 -2 -3 3 2 2 2 2
#1 2 3

#3 1

#segment tree
def yet_another_yet_another_task(a):

    n = len(a)
    preSum = [0 for i in range(n)]
    postSum = [0 for i in range(n)]

    preSum[0] = a[0]
    postSum[n-1] = a[n-1]

    for i in range(1, n):
        preSum[i] = preSum[i-1] + a[i]

    for i in range(n-2, -1, -1):
        postSum[i] = postSum[i+1] + a[i]

    #print(preSum)
    #print(postSum)

    preSumSegmentTree = SegmentTree(0, n-1, preSum)
    postSumSegmentTree = SegmentTree(0, n-1, postSum)

    st = []
    leftSum = [0 for i in range(n)]
    for i in range(n):
        j = i
        while len(st) > 0 and st[-1][0] <= a[i]:
            j = st.pop()[1]
        st.append([a[i], j])

        leftSum[i] = postSumSegmentTree.query(j, i) - postSum[i]

    st = []
    rightSum = [0 for i in range(n)]
    for i in range(n-1, -1, -1):
        j = i
        while len(st) > 0 and st[-1][0] <= a[i]:
            j = st.pop()[1]
        st.append([a[i], j])

        rightSum[i] = preSumSegmentTree.query(i, j) - preSum[i]

    #print(leftSum)
    #print(rightSum)

    res = 0
    for i in range(n):
        res = max(res, leftSum[i] + rightSum[i])

    return res



class SegmentTree:

    def __init__(self, i, j, sum):

        self.l = i
        self.r = j
        m = (i + j) // 2

        if i == j:
            self.maxVal = sum[i]
            return
        if i > j:
            return -1000000000

        self.lst = SegmentTree(i, m, sum)
        self.rst = SegmentTree(m+1, j, sum)

        if self.lst is not None and self.rst is not None:
            self.maxVal = max(self.lst.maxVal, self.rst.maxVal)
        elif self.lst is None:
            self.maxVal = self.rst.maxVal
        elif self.rst is None:
            self.maxVal = self.lst.maxVal

    def query(self, i, j):

        if j < self.l or self.r < i:
            return -1000000000

        if i <= self.l and self.r <= j:
            return self.maxVal

        ql = -1000000000
        qr = -1000000000

        if self.lst is not None:
            ql = self.lst.query(i,j)
        if self.rst is not None:
            qr = self.rst.query(i,j)

        return max(ql, qr)



#Kadane algorithm
def yet_another_yet_another_task2(a):

    res = 0
    for i in range(1, 31):

        mxr = 0
        mnr = 0
        for j in a:
            if j > i:
                mxr = 0
                mnr = 0
            else:
                mxr += j
                mnr = min(mxr, mnr)
                res = max(res, mxr - mnr - i)

    return res


if __name__ == '__main__':

    n = int(stdin.readline())
    a = list(map(int, stdin.readline().split()))

    stdout.write(str(yet_another_yet_another_task(a)) + '\n')