10
-3 4 -4 1 1 -4 -5 3 -4 -2
 10
8 9 -10 -10 -4 -3 5 9 -9 9
 6
5 -4 2 -1 2 -2
 11
3 0 1 -2 5 -5 -1 0 3 2 2
 10
4 -2 -2 -2 2 0 1 0 -4 -1
 4
2 2 -3 4
 11
-11 -7 -2 -24 30 -26 24 9 -8 -9 23
 6
30 -29 5 5 -29 30
 24
-8 -6 6 -11 -15 -7 10 -19 -6 21 14 -4 -21 -10 12 17 1 -1 5 19 2 0 -4 -23
 10
-9 -6 -1 9 -2 0 0 -1 5 0
 6
10 -8 3 3 -8 10
 10
-2 -3 -1 4 -3 2 0 1 -5 4
 5
30 -29 10 -1 10
 31
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -29 30
 7
30 -20 5 1 3 -20 30
 5
30 -29 4 -3 4
 10
-5 28 -18 -10 9 -2 11 -6 -19 30
 8
4 -10 13 -13 2 2 -11 6
 131
30 -29 29 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 28 -28 27 -26 27
 10
-4 4 0 -2 3 0 1 2 3 -4
 10
-2 -8 5 4 -1 -6 -9 6 1 -6
 7
25 -17 13 13 -25 25 -24
 10
3 -3 2 1 -4 -2 3 -2 -3 0
 10
4 -5 0 4 0 0 -3 1 1 -4
 10
0 4 4 1 -3 4 2 1 4 -1
 17
15 -13 7 8 8 1 -19 12 8 -23 -4 16 -13 -28 10 -30 -14
 4
1 1 -4 10
 11
3 -2 1 1 1 1 1 1 1 -3 4
 7
30 -29 10 10 10 -29 30
 7
25 -13 17 -23 12 12 9
 7
15 -14 10 10 10 -14 15
 10
3 0 0 -4 3 1 -2 -1 -1 4
 6
8 -7 7 -6 5 5
 10
1 -4 -4 4 -2 -3 3 0 -2 3
 15
1 -26 -6 26 7 10 -2 -4 -6 14 -9 25 9 -12 -28
 6
30 -29 10 10 -29 30
 1
6
 2
1 1
 5
0 5 -4 3 -1
 7
5 -4 3 -1 3 -4 4
 10
16 -15 13 -1 10 -2 -20 26 5 -30
 10
-1 2 0 -1 2 -1 4 3 -5 1
 7
5 -4 1 1 1 -4 5
 5
10 -3 -5 3 5
 10
4 -4 3 -2 3 -4 -2 0 1 0
 10
-5 -5 -3 1 -2 2 0 2 -3 4
 10
2 -4 -2 3 1 1 -2 -1 -3 4
 10
-4 -5 4 -3 2 -2 2 1 -1 0
 10
0 -1 4 -2 3 -2 -1 -5 -5 2
 5
19 -6 1 -11 19
 10
1 0 -4 3 -5 3 -1 2 2 -5
 7
5 -5 3 4 3 -5 5
 10
-5 2 -3 -3 -4 3 3 0 2 4
 4
2 3 -10 11
 10
27 -17 15 -22 18 17 -6 2 16 -14
 6
30 -22 6 7 -22 30
 7
30 -25 0 6 9 -2 10
 9
7 2 -1 1 1 -10 6 -1 6
 4
1 -10 1 10
 5
17 -16 12 -11 15
 35
-23 -22 23 4 -22 29 -4 -6 -28 18 -5 21 -7 -8 -11 -7 30 -25 -1 12 19 5 -8 12 -1 10 -24 -19 24 -17 -7 24 20 -22 16
 10
4 -3 1 -2 1 1 0 -4 4 -2
 10
4 -2 1 0 1 -5 -2 1 0 -5
 2
3 9
 9
11 -5 -5 1 2 3 -5 -5 11

1
 8
 1
 4
 1
 2
 15
 5
 36
 2
 3
 1
 9
 28
 4
 1
 7
 2
 1
 7
 4
 13
 1
 1
 13
 16
 1
 6
 20
 21
 20
 1
 5
 1
 44
 10
 0
 1
 0
 2
 9
 5
 2
 3
 1
 2
 2
 1
 1
 3
 3
 6
 8
 2
 29
 6
 13
 5
 1
 1
 30
 1
 1
 3
 3

import java.io.*;
import java.math.*;
import java.util.*;

public class test {
	/*
	 * array list
	 * 
	 * ArrayList<Integer> al=new ArrayList<>(); creating BigIntegers
	 * 
	 * BigInteger a=new BigInteger(); BigInteger b=new BigInteger();
	 * 
	 * hash map
	 * 
	 * HashMap<Integer,Integer> hm=new HashMap<Integer,Integer>(); for(int
	 * i=0;i<ar.length;i++) { Integer c=hm.get(ar[i]); if(hm.get(ar[i])==null) {
	 * hm.put(ar[i],1); } else { hm.put(ar[i],++c); } }
	 * 
	 * while loop
	 * 
	 * int t=sc.nextInt(); while(t>0) { t--; }
	 * 
	 * array input
	 * 
	 * int n = sc.nextInt(); int ar[] = new int[n]; for (int i = 0; i < ar.length;
	 * i++) { ar[i] = sc.nextInt(); }
	 */

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}

	static class Pair {
		int first, second;

		public Pair(int first, int second) {
			this.first = first;
			this.second = second;
		}

	}

	static class OutputWriter {
		private final PrintWriter writer;

		public OutputWriter(OutputStream outputStream) {
			writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
		}

		public OutputWriter(Writer writer) {
			this.writer = new PrintWriter(writer);
		}

		public void print(Object... objects) {
			for (int i = 0; i < objects.length; i++) {
				if (i != 0)
					writer.print(' ');
				writer.print(objects[i]);
			}
		}

		public void printLine(Object... objects) {
			print(objects);
			writer.println();
		}

		public void close() {
			writer.close();
		}

		public void flush() {
			writer.flush();
		}

	}

	private static final Scanner sc = new Scanner(System.in);
	private static final FastReader fs = new FastReader();
	private static final OutputWriter op = new OutputWriter(System.out);

	static int[] getintarray(int n) {
		int ar[] = new int[n];
		for (int i = 0; i < n; i++) {
			ar[i] = fs.nextInt();
		}
		return ar;
	}

	static long[] getlongarray(int n) {
		long ar[] = new long[n];
		for (int i = 0; i < n; i++) {
			ar[i] = fs.nextLong();
		}
		return ar;
	}

	static int[][] get2darray(int n, int m) {
		int ar[][] = new int[n][m];
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				ar[i][j] = fs.nextInt();
			}
		}
		return ar;
	}

	static Pair[] getpairarray(int n) {
		Pair ar[] = new Pair[n];
		for (int i = 0; i < n; i++) {
			ar[i] = new Pair(fs.nextInt(), fs.nextInt());
		}
		return ar;
	}

	static void printarray(int ar[]) {
		System.out.println(Arrays.toString(ar));
	}

	static boolean checkmyArray(int[] ar)

	{
		int temp = ar[0];
		for (int i = 1; i < ar.length; i++) {
			if (temp != ar[i])
				return false;
		}
		return true;
	}

	static int fact(int n) {
		int fact = 1;
		for (int i = 2; i <= n; i++) {
			fact *= i;
		}
		return fact;
	}

	static int getans(int[] a, int[] b) {
		int a1 = a[0];
		int a2 = b[0];
		int b1 = a[1];
		int b2 = b[1];
		int c1 = a[2];
		int c2 = b[2];

		if (((a1 == a2) && (b1 == b2) && (c1 == c2)))
			return 0;
		else if ((a2 - a1) == (b2 - b1) && (b2 - b1) == (c2 - c1))
			return 1;
		else if ((a2 / a1 == b2 / b1) && (b2 / b1 == c2 / c1) && (a2 / a1 == c2 / c1)
				&& (a2 % a1 == 0 && b2 % b1 == 0 && c2 % c1 == 0))
			return 1;
		else if (((a1 == a2) && (b1 == b2)) || ((a1 == a2) && (c1 == c2)) || ((c1 == c2) && (b1 == b2))) {
			return 1;
		} else if (a1 == a2) {
			if ((b2 - b1) == (c2 - c1) || ((b2 / b1 == c2 / c1) && (b2 % b1 == 0 && c2 % c1 == 0)))
				return 1;
		} else if (b1 == b2) {
			if ((a2 - a1) == (c2 - c1) || ((a2 / a1 == c2 / c1) && (a2 % a1 == 0 && c2 % c1 == 0)))
				return 1;
		} else if (c1 == c2) {
			if ((b2 - b1) == (a2 - a1) || ((b2 / b1 == a2 / a1) && (b2 % b1 == 0 && a2 % a1 == 0)))
				return 1;
		} else if ((((a2 - a1) != (b2 - b1) && (b2 - b1) != (c2 - c1) && (a2 - a1) != (c2 - c1))
				&& ((a2 / a1 != b2 / b1) && (b2 / b1 != c2 / c1) && (a2 / a1 != c2 / c1)))) {
			return 3;
		} else if ((((a2 - a1) != (b2 - b1) && (b2 - b1) != (c2 - c1) && (a2 - a1) != (c2 - c1)))) {
			if ((a2 / a1 == b2 / b1 && a2 % a1 != 0 && b2 % b1 != 0)
					|| (a2 / a1 == c2 / c1 && a2 % a1 != 0 && c2 % c1 != 0)
					|| (c2 / c1 == b2 / b1 && c2 % c1 != 0 && b2 % b1 != 0))
				return 3;

		}
		return 2;

	}

	public static void main(String[] args) {
//		int t = fs.nextInt();
////		int t = 1;
//		while (t > 0) {
//			int a[] = getintarray(3);
//			int b[] = getintarray(3);
//			int ans = getans(a, b);
//			System.out.println(ans);
//		}
//		int t = fs.nextInt();
		int t = 1;
		while (t > 0) {
			int n = fs.nextInt();
			int ar[] = getintarray(n);
//			printarray(ar);
			int prefix[] = new int[n];
			int sum = 0;
			int best = 0;
			for (int i = 0; i < ar.length; i++) {
				sum = Integer.max(ar[i], sum + ar[i]);
				best = Integer.max(best, sum);
				prefix[i] = best;
			}
			prefix[0]=ar[0];
//			printarray(prefix);
			int max[] = new int[n];
			max[0] = ar[0];
			for (int i = 1; i < ar.length; i++) {
				if(ar[i]>max[i-1])
					max[i]=ar[i];
				else
					max[i]=max[i-1];
			}
//			printarray(max);
			int dp[]=new int[n];
			for(int i=0;i<n;i++)
			{
				dp[i]=prefix[i]-max[i];
			}
//			printarray(dp);
			int m=Integer.MIN_VALUE;
			for(int i=0;i<dp.length;i++)
			{
				if(dp[i]>m)
				{
					m=dp[i];
				}
			}
			System.out.println(m);
			t--;
		}
	}

}/*
	 * 1 5 -2 -3 -1 -4 -6till here
	 */
