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.
import java.io.IOException;
import java.util.*;
import java.util.function.DoubleToIntFunction;

public class Solution {
    static int n;
    public static void main(String args[]) throws IOException {
        Scanner in = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int i,j;
        int n=in.nextInt();
        int arr[]=new int[n+1];
        long prefix[]=new long[n+2];
        long suffix[]=new long[n+2];
        for(i=1;i<=n;i++) {
            arr[i] = in.nextInt() + 30;
            prefix[i]=prefix[i-1]+arr[i]-30;
        }
        for(i=n;i>=1;i--){
            suffix[i]=suffix[i+1]+arr[i]-30;
        }
        prefix[n+1]=(suffix[0]=prefix[n]);
        int pre[]=new int[n+1];
        int next[]=new int[n+1];
        int pos[]=new int[61];
        Arrays.fill(pos,-1);
        for(i=1;i<=n;i++) {
            int f = 0;
            for (j = arr[i] + 1; j <= 60; j++) {
                if (pos[j] != -1) {
                    f = Math.max(f, pos[j]);
                }
            }
            pre[i] = f;
            pos[arr[i]] = i;
        }

        Arrays.fill(pos,-1);
        for(i=n;i>=1;i--){
            int f=n+1;
            for(j=arr[i]+1;j<=60;j++){
                if(pos[j]!=-1){
                    f=Math.min(f,pos[j]);;
                }
            }
            next[i]=f;
            pos[arr[i]]=i;
        }

        SegmentTree pst=new SegmentTree(prefix);
        SegmentTree sst=new SegmentTree(suffix);

        long ans=0;
        for(i=1;i<=n;i++){
            int x=next[i]-1;
            int y=pre[i]+1;
            long a=0,b=0;
            if(x>i)
                a=Math.max(a,pst.query(i+1,x) - prefix[i]);
            if(i>y)
                b=Math.max(b,sst.query(y,i-1)-suffix[i]);
            ans=Math.max(ans,a+b);

        }
        System.out.println(ans);



    }
}

class SegmentTree {
    long tree[];
    int N;

    public SegmentTree(long arr[]) {
        N = 1;
        while (N < arr.length)
            N = N * 2;
        tree = new long[2 * N - 1];
        for (int i = 0; i < arr.length; i++)
            tree[i + N - 1] = arr[i];
        for (int i = N - 2; i >= 0; i--)
            tree[i] = Math.max(tree[2 * i + 1] , tree[2 * i + 2]);

    }


    public long query(int l, int r) {
        return query(0, 0, N - 1, Math.min(l, r), Math.max(l, r));
    }

    public long query(int i, int s, int e, int l, int r) {
        if (l > e || r < s || s > e)
            return Integer.MIN_VALUE;
        if (s >= l && e <= r) {
            return tree[i];
        }
        int mid = (s + e) / 2;
        return Math.max(query(2 * i + 1, s, mid, l, r) , query(2 * i + 2, mid + 1, e, l, r));

    }

}