import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        c33 solver = new c33();
        solver.solve(1, in, out);
        out.close();
    }

    static class c33 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }
            long[] prefSum = new long[n + 1];
            long[] prefNSum = new long[n + 1];
            long[] gainPrefSum = new long[n + 1];
            long[] maxGainPrefSum = new long[n + 1];
            for (int i = 0; i < n; i++) {
                prefSum[i + 1] = prefSum[i] + a[i];
                prefNSum[i + 1] = prefNSum[i] - a[i];
                gainPrefSum[i + 1] = prefNSum[i + 1] - prefSum[i + 1];
                maxGainPrefSum[i + 1] = Math.max(maxGainPrefSum[i], gainPrefSum[i + 1]);
            }
            long[] sufSum = new long[n + 1];
            long[] sufNSum = new long[n + 1];
            long[] gainSufSum = new long[n + 1];
            long[] maxGainSufSum = new long[n + 1];
            for (int i = n; i > 0; i--) {
                sufSum[i - 1] = sufSum[i] + a[i - 1];
                sufNSum[i - 1] = sufNSum[i] - a[i - 1];
                gainSufSum[i - 1] = sufNSum[i - 1] - sufSum[i - 1];
                maxGainSufSum[i - 1] = Math.max(maxGainSufSum[i], gainSufSum[i - 1]);
            }
            long orig = prefSum[n];
            long ans = orig;
            for (int i = 0; i <= n; i++) {
                ans = Math.max(ans, orig + maxGainPrefSum[i] + maxGainSufSum[i]);
            }
            out.println(ans);
        }

    }

    static class InputReader {
        private BufferedReader reader;
        private StringTokenizer stt;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
        }

        public String nextLine() {
            try {
                return reader.readLine();
            } catch (IOException e) {
                return null;
            }
        }

        public String next() {
            while (stt == null || !stt.hasMoreTokens()) {
                stt = new StringTokenizer(nextLine());
            }
            return stt.nextToken();
        }

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

    }
}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Template implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws FileNotFoundException {
		try {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		} catch (Exception e) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}
	}

	class GraphBuilder {
		int n, m;
		int[] x, y;
		int index;
		int[] size;

		GraphBuilder(int n, int m) {
			this.n = n;
			this.m = m;
			x = new int[m];
			y = new int[m];
			size = new int[n];
		}

		void add(int u, int v) {
			x[index] = u;
			y[index] = v;
			size[u]++;
			size[v]++;
			index++;
		}

		int[][] build() {
			int[][] graph = new int[n][];
			for (int i = 0; i < n; i++) {
				graph[i] = new int[size[i]];
			}
			for (int i = m - 1; i >= 0; i--) {
				graph[x[i]][--size[x[i]]] = y[i];
				graph[y[i]][--size[y[i]]] = x[i];
			}
			return graph;
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			try {
				tok = new StringTokenizer(in.readLine());
			} catch (Exception e) {
				return null;
			}
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	int[] readIntArray(int size) throws IOException {
		int[] res = new int[size];
		for (int i = 0; i < size; i++) {
			res[i] = readInt();
		}
		return res;
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	<T> List<T>[] createGraphList(int size) {
		List<T>[] list = new List[size];
		for (int i = 0; i < size; i++) {
			list[i] = new ArrayList<>();
		}
		return list;
	}

	public static void main(String[] args) {
		new Template().run();
		// new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
	}

	long timeBegin, timeEnd;

	void time() {
		timeEnd = System.currentTimeMillis();
		System.err.println("Time = " + (timeEnd - timeBegin));
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
	}

	public void run() {
		try {
			timeBegin = System.currentTimeMillis();
			memoryTotal = Runtime.getRuntime().freeMemory();
			init();
			solve();
			out.close();
			if (System.getProperty("ONLINE_JUDGE") == null) {
				time();
				memory();
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	void solve() throws IOException {
		int n = readInt();
		int[] a = readIntArray(n);
		int[] prefixMin = new int[a.length];
		int p = 0;
		for (int i=0;i<n;i++) {
			p += a[i];
			prefixMin[i] = p;
			if (i > 0) prefixMin[i] = Math.min(prefixMin[i], prefixMin[i - 1]);
		}
		int[] suffixMin = new int[a.length];
		int s = 0;
		for (int i=n-1;i>=0;i--) {
			s += a[i];
			suffixMin[i] = s;
			if (i < n - 1) {
				suffixMin[i] = Math.min(suffixMin[i], suffixMin[i + 1]);
			}
		}
		int sum = 0;
		for (int i=0;i<n;i++) {
			sum += a[i];
		}
		int bestAnswer = Integer.MIN_VALUE;
		for (int i=0;i<n;i++) {
			bestAnswer = Math.max(bestAnswer, sum -2 * prefixMin[i]);
			bestAnswer = Math.max(bestAnswer, sum -2 * suffixMin[i]);

			if (i + 1 < n) {
				bestAnswer = Math.max(bestAnswer, sum -2 * prefixMin[i] - 2 * suffixMin[i + 1]);
			}
		}
		out.println(bestAnswer);

	}

}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

public class Template implements Runnable {

	BufferedReader in;
	PrintWriter out;
	StringTokenizer tok = new StringTokenizer("");

	void init() throws FileNotFoundException {
		try {
			in = new BufferedReader(new FileReader("input.txt"));
			out = new PrintWriter("output.txt");
		} catch (Exception e) {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
		}
	}

	class GraphBuilder {
		int n, m;
		int[] x, y;
		int index;
		int[] size;

		GraphBuilder(int n, int m) {
			this.n = n;
			this.m = m;
			x = new int[m];
			y = new int[m];
			size = new int[n];
		}

		void add(int u, int v) {
			x[index] = u;
			y[index] = v;
			size[u]++;
			size[v]++;
			index++;
		}

		int[][] build() {
			int[][] graph = new int[n][];
			for (int i = 0; i < n; i++) {
				graph[i] = new int[size[i]];
			}
			for (int i = m - 1; i >= 0; i--) {
				graph[x[i]][--size[x[i]]] = y[i];
				graph[y[i]][--size[y[i]]] = x[i];
			}
			return graph;
		}
	}

	String readString() throws IOException {
		while (!tok.hasMoreTokens()) {
			try {
				tok = new StringTokenizer(in.readLine());
			} catch (Exception e) {
				return null;
			}
		}
		return tok.nextToken();
	}

	int readInt() throws IOException {
		return Integer.parseInt(readString());
	}

	int[] readIntArray(int size) throws IOException {
		int[] res = new int[size];
		for (int i = 0; i < size; i++) {
			res[i] = readInt();
		}
		return res;
	}

	long readLong() throws IOException {
		return Long.parseLong(readString());
	}

	double readDouble() throws IOException {
		return Double.parseDouble(readString());
	}

	<T> List<T>[] createGraphList(int size) {
		List<T>[] list = new List[size];
		for (int i = 0; i < size; i++) {
			list[i] = new ArrayList<>();
		}
		return list;
	}

	public static void main(String[] args) {
		new Template().run();
		// new Thread(null, new Template(), "", 1l * 200 * 1024 * 1024).start();
	}

	long timeBegin, timeEnd;

	void time() {
		timeEnd = System.currentTimeMillis();
		System.err.println("Time = " + (timeEnd - timeBegin));
	}

	long memoryTotal, memoryFree;

	void memory() {
		memoryFree = Runtime.getRuntime().freeMemory();
		System.err.println("Memory = " + ((memoryTotal - memoryFree) >> 10) + " KB");
	}

	public void run() {
		try {
			timeBegin = System.currentTimeMillis();
			memoryTotal = Runtime.getRuntime().freeMemory();
			init();
			solve();
			out.close();
			if (System.getProperty("ONLINE_JUDGE") == null) {
				time();
				memory();
			}
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(-1);
		}
	}

	void solve() throws IOException {
		int n = readInt();
		int[] a = readIntArray(n);
		int[] prefixMin = new int[a.length];
		int p = 0;
		for (int i=0;i<n;i++) {
			p += a[i];
			prefixMin[i] = p;
			if (i > 0) prefixMin[i] = Math.min(prefixMin[i], prefixMin[i - 1]);
		}
		int[] suffixMin = new int[a.length];
		int s = 0;
		for (int i=n-1;i>=0;i--) {
			s += a[i];
			suffixMin[i] = s;
			if (i < n - 1) {
				suffixMin[i] = Math.min(suffixMin[i], suffixMin[i + 1]);
			}
		}
		int sum = 0;
		for (int i=0;i<n;i++) {
			sum += a[i];
		}
		int bestAnswer = sum;
		for (int i=0;i<n;i++) {
			bestAnswer = Math.max(bestAnswer, sum -2 * prefixMin[i]);
			bestAnswer = Math.max(bestAnswer, sum -2 * suffixMin[i]);

			if (i + 1 < n) {
				bestAnswer = Math.max(bestAnswer, sum -2 * prefixMin[i] - 2 * suffixMin[i + 1]);
			}
		}
		out.println(bestAnswer);

	}

}


        import java.io.*;

        import java.math.BigInteger;
    import java.text.DecimalFormat;
    import java.util.*;

    //import Submatrix.InputReader;

         public class Main {
        	public static InputReader in;
            public static PrintWriter pw;

        	public static void main(String args[]) {
        		new Thread(null, new Runnable() {
                    public void run() {
                        try{
                            solve();
                        }
                        catch(Exception e){
                            e.printStackTrace();
                        }
                    }
                }, "1", 1 << 26).start();
            }
        	static ArrayList<Integer> g[];
        	static boolean visited[];
        	static int par[];
        	static int degree[];
        	static int edjes=0;
        	static int start=-1;
        	static int end=-1;
        	static int time1[];
        	static int time2[];
        	static int glob=0;
        	static ArrayList<Integer> levels[];
            static int max=0;
            static int lev=1;
            static ArrayList<Integer> nodes[];
            static ArrayList<Integer> values[];
            static int depth[];
            static boolean found=false;
            static int sum1=0;
            static int pre[][];
            static int subtree[];
           static long mul[];
           static long d[]=new long[1000000];
            static long Cardinality[];
            static int k;
            public static void solve(){

        		 in = new InputReader(System.in);
        		 pw = new PrintWriter(System.out);
                 int n=in.nextInt();
                 int a[]=in.nextIntArray(n);
                 int sm[]=new int[n];
                 int sm2[]=new int[n];
                 int pr[]=new int[n];
                 for(int i=0;i<n;i++)
                 {
                	sm[i] = a[i];
             		if (i>0)sm[i]+= sm[i - 1];
             		pr[i]=Math.max(sm[i],-sm[i]);
             		if (i>0)pr[i]=Math.max(pr[i],pr[i-1]+a[i]);
                 }
                 int cr[]=new int[n];
                 for(int i=n-1;i>=0;i--)
                 {
                	 if(i==n-1)
                		 sm2[i]=a[i];
                	 else
             		sm2[i]+=sm2[i+1]+a[i];
             		cr[i] =Math.max(sm2[i],-sm2[i]);
             		if (i<n-1) cr[i] = Math.max(cr[i], cr[i +1] + a[i]);
                 }

                 for(int i=0;i<n-1;i++)
                max=Math.max(max,pr[i]+cr[i+1]);
                 max=Math.max(max, cr[n-1]);

     System.out.println(max);
            }

			public static long gcd(long a, long b) {
      		  if (b == 0) return a;
    		  return gcd(b, a%b);
    		}

             static class Pair implements Comparable<Pair>{
            	int now;
            		int aft;
            		int index;
            		Pair(int ver,int weight,int index){
            	     	this.now=ver;
            			this.aft=weight;
            			this.index=index;
            		}
            		@Override
            		public int compareTo(Pair o) {

                            	return (int)(o.now-now);
            		}

            	}
        	static class InputReader {

        		private InputStream stream;
        		private byte[] buf = new byte[8192];
        		private int curChar, snumChars;
        		private SpaceCharFilter filter;

        		public InputReader(InputStream stream) {
        			this.stream = stream;
        		}

        		public int snext() {
        			if (snumChars == -1)
        				throw new InputMismatchException();
        			if (curChar >= snumChars) {
        				curChar = 0;
        				try {
        					snumChars = stream.read(buf);
        				} catch (IOException e) {
        					throw new InputMismatchException();
        				}
        				if (snumChars <= 0)
        					return -1;
        			}
        			return buf[curChar++];
        		}

        		public   int nextInt() {
        			int c = snext();
        			while (isSpaceChar(c))
        				c = snext();
        			int sgn = 1;
        			if (c == '-') {
        				sgn = -1;
        				c = snext();
        			}
        			int res = 0;
        			do {
        				if (c < '0' || c > '9')
        					throw new InputMismatchException();
        				res *= 10;
        				res += c - '0';
        				c = snext();
        			} while (!isSpaceChar(c));
        			return res * sgn;
        		}

        		public long nextLong() {
        			int c = snext();
        			while (isSpaceChar(c))
        				c = snext();
        			int sgn = 1;
        			if (c == '-') {
        				sgn = -1;
        				c = snext();
        			}
        			long res = 0;
        			do {
        				if (c < '0' || c > '9')
        					throw new InputMismatchException();
        				res *= 10;
        				res += c - '0';
        				c = snext();
        			} while (!isSpaceChar(c));
        			return res * sgn;
        		}

        		public int[] nextIntArray(int n) {
        			int a[] = new int[n];
        			for (int i = 0; i < n; i++)
        				a[i] = nextInt();
        			return a;
        		}

        		public String readString() {
        			int c = snext();
        			while (isSpaceChar(c))
        				c = snext();
        			StringBuilder res = new StringBuilder();
        			do {
        				res.appendCodePoint(c);
        				c = snext();
        			} while (!isSpaceChar(c));
        			return res.toString();
        		}

        		public boolean isSpaceChar(int c) {
        			if (filter != null)
        				return filter.isSpaceChar(c);
        			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        		}

        		public interface SpaceCharFilter {
        			public boolean isSpaceChar(int ch);
        		}
        	}
        }


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CWonderfulRandomizedSum solver = new CWonderfulRandomizedSum();
        solver.solve(1, in, out);
        out.close();
    }

    static class CWonderfulRandomizedSum {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] A = in.nextIntArray(n);
            long[] pres = new long[n + 1];
            long[] predp = new long[n];
            long[] sufdp = new long[n + 1];

            for (int i = 0; i < n; i++) {
                pres[i + 1] = pres[i] + A[i];
            }

            for (int i = 0; i < n; i++) {
                predp[i] = Math.max(-pres[i + 1], ((i > 0) ? predp[i - 1] : 0) + A[i]);
            }
            long maxs = 0;
            for (int i = n - 1; i >= 0; i--) {
                // l = i R = n - 1
                long sufs = pres[n] - pres[i];
                sufdp[i] = Math.max(-sufs, sufdp[i + 1] + A[i]);
            }

            long ans = 0;
            for (int i = 0; i < n; i++) {
                ans = Math.max(predp[i] + sufdp[i + 1], ans);
            }
            out.print(ans);

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int[] nextIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
                array[i] = nextInt();
            return array;
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CWonderfulRandomizedSum solver = new CWonderfulRandomizedSum();
        solver.solve(1, in, out);
        out.close();
    }

    static class CWonderfulRandomizedSum {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int[] A = in.nextIntArray(n);
            long[] pres = new long[n + 1];
            long[] predp = new long[n];
            long[] sufdp = new long[n + 1];

            for (int i = 0; i < n; i++) {
                pres[i + 1] = pres[i] + A[i];
            }

            for (int i = 0; i < n; i++) {
                predp[i] = Math.max(-pres[i + 1], ((i > 0) ? predp[i - 1] : 0) + A[i]);
            }
            long maxs = 0;
            for (int i = n - 1; i >= 0; i--) {
                // l = i R = n - 1
                long sufs = pres[n] - pres[i];
                sufdp[i] = Math.max(-sufs, sufdp[i + 1] + A[i]);
            }

            long ans = 0;
            for (int i = 0; i < n - 1; i++) {
                ans = Math.max(predp[i] + sufdp[i + 1], ans);
            }
            out.print(ans);

        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        private boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public int[] nextIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++)
                array[i] = nextInt();
            return array;
        }

    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair<A, B> {
	A first;
	B second;

	Pair(A first, B second) {
		this.first = first;
		this.second = second;
	}

}

class TaskB {
	int INF = (int) 1e9 + 7;
	int MAX_N = (int) 2e4 + 5;
	long mod = (long) 1e8;

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int n = in.nextInt();
		int arr[] = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum += arr[i];
		}
		int sum1 = arr[0];
		int start = arr[0];
		int max = 0;
		for (int i = 0; i < arr.length; i++) {
			sum1 += arr[i];
			if (sum1 < 0) {
				sum1 = 0;
			}
			max = Math.max(max, sum1);

		}
		pw.println(2 * max - sum);

	}

	long fib(int N) {
		long fib[] = new long[N + 1];
		fib[0] = 1;
		fib[1] = 1;
		for (int i = 2; i <= N; i++) {
			fib[i] = (fib[i - 1] + fib[i - 2]) % mod;
		}
		return fib[N] % mod;
	}

	long sum(int i, int j, long arr[]) {
		long sum = 0;
		for (int k = i; k <= j; k++) {
			sum += arr[k];
		}
		return sum;
	}

	boolean FirstRow_Col(Pair<Integer, Integer> pair) {
		return pair.first == 0 || pair.second == 0;
	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

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

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

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

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


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */
public class Main {
	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), true);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.flush();
		out.close();
	}
}

class Pair<A, B> {
	A first;
	B second;

	Pair(A first, B second) {
		this.first = first;
		this.second = second;
	}

}

class TaskB {
	int INF = (int) 1e9 + 7;
	int MAX_N = (int) 2e4 + 5;
	long mod = (long) 1e8;

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int n = in.nextInt();
		int arr[] = new int[n];
		for (int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		int sum = 0;
		for (int i = 0; i < n; i++) {
			sum += arr[i];
		}
		int sum1 = 0;
		int max = 0;
		for (int i = 0; i < arr.length; i++) {
			sum1 += arr[i];
			if (sum1 < 0) {
				sum1 = 0;
			}
			max = Math.max(max, sum1);

		}
		pw.println(2 * max - sum);

	}

	long fib(int N) {
		long fib[] = new long[N + 1];
		fib[0] = 1;
		fib[1] = 1;
		for (int i = 2; i <= N; i++) {
			fib[i] = (fib[i - 1] + fib[i - 2]) % mod;
		}
		return fib[N] % mod;
	}

	long sum(int i, int j, long arr[]) {
		long sum = 0;
		for (int k = i; k <= j; k++) {
			sum += arr[k];
		}
		return sum;
	}

	boolean FirstRow_Col(Pair<Integer, Integer> pair) {
		return pair.first == 0 || pair.second == 0;
	}

	int __gcd(int a, int b) {
		if (b == 0)
			return a;
		return __gcd(b, a % b);

	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

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

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

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

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


/*
 *
 * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)
 * Dhirubhai Ambani Institute of Information And Communication Technology
 *
 */

import java.util.*;
import java.io.*;
import java.lang.*;

public class Code120
{

	private static long mod = 1000000007;
	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static ArrayList<Integer> primeFactorization(int n)
	{
		ArrayList<Integer> a =new ArrayList<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(i*i);j<n;j++)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long GCD(long a,long b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}
	}

	public static boolean isPrime(int n)
	{
		for(int i=2;(i*i)<=n;i++)
		{
			if(n%i==0 && i!=n)
				return false;
		}
		return true;
	}
	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int n = in.nextInt();
		int[] a = in.nextIntArray(n);

		int[] suf = new int[n];
		suf[n-1] = a[n-1];

		for(int i=n-2;i>=0;i--)
			suf[i] = a[i] + suf[i+1];

		int sum = suf[0];
		for(int i=n-2;i>=0;i--)
			suf[i] = Math.min(suf[i], suf[i+1]);

		int ans  =  Math.max(sum, sum - 2*suf[0]);

		int curr = 0;
		for(int i=0;i<n-1;i++)
		{
			curr += a[i];
			int now = sum - 2*curr;
			now -= Math.min(0, 2*suf[i+1]);
			ans = Math.max(ans, now);
		}

		pw.println(ans);
		pw.flush();
		pw.close();
	}
}


/*
 *
 * @Author  Ajudiya_13(Bhargav Girdharbhai Ajudiya)
 * Dhirubhai Ambani Institute of Information And Communication Technology
 *
 */

import java.util.*;
import java.io.*;
import java.lang.*;

public class Code120
{

	private static long mod = 1000000007;
	static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;
		private SpaceCharFilter filter;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int snext() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = snext();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res *= 10;
				res += c - '0';
				c = snext();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public int[] nextIntArray(int n) {
			int a[] = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public String readString() {
			int c = snext();
			while (isSpaceChar(c)) {
				c = snext();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = snext();
			while (isSpaceChar(c))
				c = snext();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = snext();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			if (filter != null)
				return filter.isSpaceChar(c);
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

		public interface SpaceCharFilter {
			public boolean isSpaceChar(int ch);
		}
	}

	public static int[] suffle(int[] a,Random gen)
	{
		int n = a.length;
		for(int i=0;i<n;i++)
		{
			int ind = gen.nextInt(n-i)+i;
			int temp = a[ind];
			a[ind] = a[i];
			a[i] = temp;
		}
		return a;
	}

	public static void swap(int a, int b){
		int temp = a;
		a = b;
		b = temp;
	}

	public static ArrayList<Integer> primeFactorization(int n)
	{
		ArrayList<Integer> a =new ArrayList<Integer>();
		for(int i=2;i*i<=n;i++)
		{
			while(n%i==0)
			{
				a.add(i);
				n/=i;
			}
		}
		if(n!=1)
			a.add(n);
		return a;
	}

	public static void sieve(boolean[] isPrime,int n)
	{
		for(int i=1;i<n;i++)
			isPrime[i] = true;

		isPrime[0] = false;
		isPrime[1] = false;

		for(int i=2;i*i<n;i++)
		{
			if(isPrime[i] == true)
			{
				for(int j=(i*i);j<n;j++)
					isPrime[j] = false;
			}
		}
	}

	public static int GCD(int a,int b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long GCD(long a,long b)
	{
		if(b==0)
			return a;
		else
			return GCD(b,a%b);
	}

	public static long LCM(long a,long b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int LCM(int a,int b)
	{
		return (a*b)/GCD(a,b);
	}

	public static int binaryExponentiation(int x,int n)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static long binaryExponentiation(long x,long n)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=result * x;
	        x=x*x;
	        n=n/2;
	    }
	    return result;
	}

	public static int modularExponentiation(int x,int n,int M)
	{
	    int result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static long modularExponentiation(long x,long n,long M)
	{
	    long result=1;
	    while(n>0)
	    {
	        if(n % 2 ==1)
	            result=(result * x)%M;
	        x=(x*x)%M;
	        n=n/2;
	    }
	    return result;
	}

	public static int modInverse(int A,int M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	public static long modInverse(long A,long M)
	{
	    return modularExponentiation(A,M-2,M);
	}

	static class pair implements Comparable<pair>
	{
		Integer x, y;
		pair(int x,int y)
		{
			this.x=x;
			this.y=y;
		}

		public int compareTo(pair o) {
			int result = x.compareTo(o.x);
			if(result==0)
				result = y.compareTo(o.y);

			return result;
		}
	}

	public static boolean isPrime(int n)
	{
		for(int i=2;(i*i)<=n;i++)
		{
			if(n%i==0 && i!=n)
				return false;
		}
		return true;
	}
	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int n = in.nextInt();
		int[] a = in.nextIntArray(n);

		int i;
		int sum = 0;
		for(i=0;i<n;i++)
		{
			if(a[i]>0)
				break;
			else
				sum+=Math.abs(a[i]);
		}

		int j = 0;
		int sum1  = 0;
		for(j=n-1;j>=0;j--)
		{
			if(a[j]>0)
				break;
			else
				sum1+=Math.abs(a[j]);
		}

		if(j<i)
			pw.println(Math.max(sum, sum1));

		else
		{
			int sum2 = 0;
			for(int k=i;k<=j;k++)
				sum2 += a[k];

			pw.println(sum+sum1+sum2);
		}
		pw.flush();
		pw.close();
	}
}


import javafx.util.Pair;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    IIO io;

    Main(IIO io) {
        this.io = io;
    }

    public static void main(String[] args) throws IOException {

        ConsoleIO io = new ConsoleIO();
        Main m = new Main(io);
        m.solve();
        io.flush();

//        Tester test = new Tester();test.run();
    }

    public void solve() {
        int n = io.readInt();
        int[] a = io.readIntArray();
        int[] s1 = new int[n+1];
        int[] s2 = new int[n+1];
        int c1 = 0,c2=0,m1=0,m2=0;
        for(int i = 0;i<n;i++) {
            c1 -= a[i];
            c2 -= a[n - 1 - i];
            s1[i+1] = Math.max(s1[i]+a[i], c1);
            s2[i+1] = Math.max(s2[i]+a[n-1-i], c2);
        }
        int res = 0;
        for(int i =0;i<=n;i++)
            res = Math.max(res, s1[i]+s2[n-i]);
        io.writeLine(Integer.toString(res));
    }

}

class ConsoleIO extends BaseIO {
    BufferedReader br;
    PrintWriter out;
    public ConsoleIO(){
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
    }
    public void flush(){
        this.out.close();
    }
    public void writeLine(String s) {
        this.out.println(s);
    }
    public void writeInt(int a) {
        this.out.print(a);
        this.out.print(' ');
    }
    public void writeWord(String s){
        this.out.print(s);
    }
    public String readLine() {
        try {
            return br.readLine();
        }
        catch (Exception ex){
            return "";
        }
    }
    public int read(){
        try {
            return br.read();
        }
        catch (Exception ex){
            return -1;
        }
    }
}
abstract class BaseIO implements IIO {

    public long readLong() {
        return Long.parseLong(this.readLine());
    }

    public int readInt() {
        return Integer.parseInt(this.readLine());
    }

    public int[] readIntArray() {
        String line = this.readLine();
        String[] nums = line.split(" ");
        int[] res = new int[nums.length];
        for (int i = 0; i < nums.length; i++) {
            res[i] = Integer.parseInt(nums[i]);
        }
        return res;
    }
    public long[] readLongArray() {
        String line = this.readLine();
        String[] nums = line.split(" ");
        long[] res = new long[nums.length];
        for (int i = 0; i < nums.length; i++) {
            res[i] = Long.parseLong(nums[i]);
        }
        return res;
    }
}
interface IIO {
    void writeLine(String s);
    void writeInt(int a);
    void writeWord(String s);
    String readLine();
    long readLong();
    int readInt();
    int read();
    int[] readIntArray();
    long[] readLongArray();
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Zimba
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		CWonderfulRandomizedSum solver = new CWonderfulRandomizedSum();
		solver.solve(1, in, out);
		out.close();
	}

	static class CWonderfulRandomizedSum {
		int n;
		PrintWriter out;
		InputReader in;

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int t, i, j, tt, k;
			this.out = out;
			this.in = in;
			n = in.nextInt();
			long a[] = new long[n];
			long hp = 0;
			long ss = 0;
			long mx = 0;
			for (i = 0; i < n; i++) {
				a[i] = in.nextLong();
				hp += a[i];
				ss += a[i];
				if (ss < 0)
					ss = 0;
				mx = Math.max(ss, mx);
			}
			pn(-hp + 2 * mx);
		}

		void pn(long zx) {
			out.println(zx);
		}

	}

	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1) {
				throw new UnknownError();
			}
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new UnknownError();
				}
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

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

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

		public String next() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));

			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Zimba
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		CWonderfulRandomizedSum solver = new CWonderfulRandomizedSum();
		solver.solve(1, in, out);
		out.close();
	}

	static class CWonderfulRandomizedSum {
		int n;
		PrintWriter out;
		InputReader in;

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int t, i, j, tt, k;
			this.out = out;
			this.in = in;
			n = in.nextInt();
			long a[] = new long[n];
			for (i = 0; i < n; i++) {
				a[i] = in.nextLong();
			}
			long pref[] = new long[n];
			pref[0] = a[0];

			long pre[] = new long[n];
			long suff[] = new long[n];
			boolean fl = false;
			long pq = -1;
			long gg = 0;
			long kp = 0;
			for (i = 0; i < n; i++) {
				kp += a[i];
				if (fl == false) {
					pq = a[i] * -1;
					pre[i] = pq;
					fl = true;
				} else {
					long og = pq + gg + a[i];
					long gf = (kp) * -1;
					if (gf >= og) {
						pq = (kp) * -1;
						gg = 0;
						pre[i] = pq;
					} else {
						gg += a[i];
						pre[i] = og;
					}
				}
			}
			fl = false;
			pq = -1;
			gg = 0;
			kp = 0;
			for (i = n - 1; i >= 0; i--) {
				kp += a[i];
				if (fl == false) {
					pq = a[i] * -1;
					suff[i] = pq;
					fl = true;
				} else {
					long og = pq + gg + a[i];
					long gf = (kp) * -1;
					if (gf >= og) {
						pq = (kp) * -1;
						gg = 0;
						suff[i] = pq;
					} else {
						gg += a[i];
						suff[i] = og;
					}
				}
			}
			long mx = kp;
			for (i = 0; i < n - 1; i++) {
				mx = Math.max(pre[i] + suff[i + 1], mx);
			}
			if (n == 1) {
				mx = Math.max(a[0], a[0] * -1);
			}
			pn(mx);
		}

		void pn(long zx) {
			out.println(zx);
		}

	}

	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1) {
				throw new UnknownError();
			}
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new UnknownError();
				}
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

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

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

		public String next() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));

			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Zimba
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		CWonderfulRandomizedSum solver = new CWonderfulRandomizedSum();
		solver.solve(1, in, out);
		out.close();
	}

	static class CWonderfulRandomizedSum {
		int n;
		PrintWriter out;
		InputReader in;

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int t, i, j, tt, k;
			this.out = out;
			this.in = in;
			n = in.nextInt();
			long a[] = new long[n];
			for (i = 0; i < n; i++) {
				a[i] = in.nextLong();
			}
			long pref[] = new long[n];
			pref[0] = a[0];

			long pre[] = new long[n];
			long suff[] = new long[n];
			boolean fl = false;
			long pq = -1;
			long gg = 0;
			long kp = 0;
			for (i = 0; i < n; i++) {
				kp += a[i];
				if (fl == false) {
					pq = a[i] * -1;
					pre[i] = pq;
					fl = true;
				} else {
					long og = pq + gg + a[i];
					long gf = (kp) * -1;
					if (gf >= og) {
						pq = (kp) * -1;
						gg = 0;
						pre[i] = pq;
					} else {
						gg += a[i];
						pre[i] = og;
					}
				}
			}
			fl = false;
			pq = -1;
			gg = 0;
			kp = 0;
			for (i = n - 1; i >= 0; i--) {
				kp += a[i];
				if (fl == false) {
					pq = a[i] * -1;
					suff[i] = pq;
					fl = true;
				} else {
					long og = pq + gg + a[i];
					long gf = (kp) * -1;
					if (gf >= og) {
						pq = (kp) * -1;
						gg = 0;
						suff[i] = pq;
					} else {
						gg += a[i];
						suff[i] = og;
					}
				}
			}
			long mx = kp;
			for (i = 0; i < n - 1; i++) {
				mx = Math.max(pre[i] + suff[i + 1], mx);
			}
			pn(mx);
		}

		void pn(long zx) {
			out.println(zx);
		}

	}

	static class InputReader {
		private InputStream stream;
		private byte[] buf = new byte[1024];
		private int curChar;
		private int numChars;

		public InputReader(InputStream stream) {
			this.stream = stream;
		}

		public int read() {
			if (numChars == -1) {
				throw new UnknownError();
			}
			if (curChar >= numChars) {
				curChar = 0;
				try {
					numChars = stream.read(buf);
				} catch (IOException e) {
					throw new UnknownError();
				}
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

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

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

		public String next() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuffer res = new StringBuffer();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));

			return res.toString();
		}

		private boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

	}
}


import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class CodeForces {
    public static void main(String[] args) {
        FastIO io = new FastIO();

        int n = io.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = io.nextInt();
        }

        int leftIndex = -1;
        int leftValue = 0;
        int leftSum = 0;
        int leftInvertedSum = 0;

        for (int i = 0; i < n; i++) {
            leftSum += a[i];
            leftInvertedSum -= a[i];

            if (leftInvertedSum > leftSum && leftInvertedSum > leftValue) {
                leftIndex = i;
                leftValue = leftInvertedSum;
            }
        }

        int rightIndex = n;
        int rightValue = 0;
        int rightSum = 0;
        int rightInvertedSum = 0;

        for (int i = n - 1; i >= 0; i--) {
            rightSum += a[i];
            rightInvertedSum -= a[i];

            if (rightInvertedSum > rightSum && rightInvertedSum > rightValue) {
                rightIndex = i;
                rightValue = rightInvertedSum;
            }
        }

        int middleSum = 0;

        if (leftIndex >= rightIndex) {
            if (leftInvertedSum > rightInvertedSum) {
                rightIndex = n;
                rightValue = 0;
                rightSum = 0;
                rightInvertedSum = 0;

                for (int i = n - 1; i > leftIndex; i--) {
                    rightSum += a[i];
                    rightInvertedSum -= a[i];

                    if (rightInvertedSum > rightSum && rightInvertedSum > rightValue) {
                        rightIndex = i;
                        rightValue = rightInvertedSum;
                    }
                }
            } else {
                leftIndex = -1;
                leftValue = 0;
                leftSum = 0;
                leftInvertedSum = 0;

                for (int i = 0; i < rightIndex; i++) {
                    leftSum += a[i];
                    leftInvertedSum -= a[i];

                    if (leftInvertedSum > leftSum && leftInvertedSum > leftValue) {
                        leftIndex = i;
                        leftValue = leftInvertedSum;
                    }
                }
            }
        }

        for (int i = leftIndex + 1; i < rightIndex; i++) {
            middleSum += a[i];
        }

        io.println(leftValue + middleSum + rightValue);

        io.close();
    }

    static class FastIO extends PrintWriter {
        BufferedReader br;
        StringTokenizer st;

        public FastIO() {
            super(new BufferedOutputStream(System.out));
            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 nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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


import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class CodeForces {
    public static void main(String[] args) {
        FastIO io = new FastIO();

        int n = io.nextInt();

        int[] a = new int[n];
        int total = 0;
        for (int i = 0; i < n; i++) {
            a[i] = io.nextInt();
            total += a[i];
        }

        int max = 0;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i];
            if (sum < 0)
                sum = 0;
            max = Math.max(max, sum);
        }

        io.println(2 * max - total);

        io.close();
    }

    static class FastIO extends PrintWriter {
        BufferedReader br;
        StringTokenizer st;

        public FastIO() {
            super(new BufferedOutputStream(System.out));
            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 nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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


import java.io.*;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public class CodeForces {
    public static void main(String[] args) {
        FastIO io = new FastIO();

        int n = io.nextInt();

        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = io.nextInt();
        }

        int leftIndex = -1;
        int leftValue = 0;
        int leftSum = 0;
        int leftInvertedSum = 0;

        for (int i = 0; i < n; i++) {
            leftSum += a[i];
            leftInvertedSum -= a[i];

            if (leftInvertedSum > leftSum && leftInvertedSum > leftValue) {
                leftIndex = i;
                leftValue = leftInvertedSum;
            }
        }

        int rightIndex = n;
        int rightValue = 0;
        int rightSum = 0;
        int rightInvertedSum = 0;

        for (int i = n - 1; i > leftIndex; i--) {
            rightSum += a[i];
            rightInvertedSum -= a[i];

            if (rightInvertedSum > rightSum && rightInvertedSum > rightValue) {
                rightIndex = i;
                rightValue = rightInvertedSum;
            }
        }

        int middleSum = 0;

        for (int i = leftIndex + 1; i < rightIndex; i++) {
            middleSum += a[i];
        }

        io.println(leftValue + middleSum + rightValue);

        io.close();
    }

    static class FastIO extends PrintWriter {
        BufferedReader br;
        StringTokenizer st;

        public FastIO() {
            super(new BufferedOutputStream(System.out));
            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 nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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


import java.io.*;
import java.util.*;
public final class random_sum
{
    static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	static FastScanner sc=new FastScanner(br);
    static PrintWriter out=new PrintWriter(System.out);
	static Random rnd=new Random();

    public static void main(String args[]) throws Exception
    {
		int n=sc.nextInt();long[] a=new long[n+1],pre=new long[n+1];long sum=0,max=Long.MIN_VALUE;
		for(int i=1;i<=n;i++)
		{
			a[i]=sc.nextLong();sum+=a[i];pre[i]=sum;
		}
		max=sum;long curr=0;long[] val=new long[n+1];
		for(int i=1;i<=n;i++)
		{
			curr+=(a[i]*-1);val[i]=curr;
			max=Math.max(max,curr+pre[n]-pre[i]);
		}
		curr=0;
		for(int i=n;i>=1;i--)
		{
			curr+=(a[i]*-1);
			max=Math.max(max,curr+pre[i-1]);
		}
		long curr_min=0,curr1=0,curr2=0,val1=0,val2=0;int pos=-1;
		for(int i=n;i>=1;i--)
		{
			//out.println(i+" "+val[i]+" "+val1+" "+val2);
			if(curr_min<0)
			{
				max=Math.max(max,val[i]+(val1*-1)+(val2*-1)+pre[pos-1]-pre[i]);
			}
			if(a[i]>=0)
			{
				curr1+=a[i];
			}
			else
			{
				curr2+=a[i];
			}
			long now=curr1-Math.abs(curr2);
			if(now<curr_min)
			{
				curr_min=now;pos=i;val1=curr1;val2=curr2;
			}
		}
		out.println(max);out.close();
    }
}
class FastScanner
{
    BufferedReader in;
    StringTokenizer st;

    public FastScanner(BufferedReader in) {
        this.in = in;
    }

    public String nextToken() throws Exception {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }

	public String next() throws Exception {
		return nextToken().toString();
	}

    public int nextInt() throws Exception {
        return Integer.parseInt(nextToken());
    }

    public long nextLong() throws Exception {
        return Long.parseLong(nextToken());
    }

    public double nextDouble() throws Exception {
        return Double.parseDouble(nextToken());
    }
}


import java.io.*;
import java.util.*;
import java.util.function.*;
import java.lang.*;

public class Main {
    final static String fileName = "";
    final static boolean useFiles = false;

    public static void main(String[] args) throws FileNotFoundException {
        InputStream inputStream;
        OutputStream outputStream;
        if (useFiles) {
            inputStream = new FileInputStream(fileName + ".in");
            outputStream = new FileOutputStream(fileName + ".out");
        } else {
            inputStream = System.in;
            outputStream = System.out;
        }
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task(in, out);
        Debug.out = out;
        solver.solve();
        out.close();
    }
}
class Task {
    public void solve() {
        int n = in.nextInt();
        int[] a = new int[n];
        int[] pref = new int[n], suff = new int[n];
        int all = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            all += a[i];
        }
        int sum = 0;
        int min = 1 << 30;
        for (int i = 0; i < n; i++) {
            sum += a[i];
            min = Math.min(sum, min);
            pref[i] = min;
        }
        min = 1 << 30;
        sum = 0;
        for (int i = n - 1; i >= 0; i--) {
            sum += a[i];
            min = Math.min(sum, min);
            suff[i] = min;
        }
        int result = Math.abs(all);
        for (int i = 0; i < n - 1; i++){
            int add = Math.max(0, -2 * pref[i]) + Math.max(0, -2 * suff[i + 1]);
            result = Math.max(result, all + add);
        }
        out.println(result);
    }

    private InputReader in;
    private PrintWriter out;

    Task(InputReader in, PrintWriter out) {
        this.in = in;
        this.out = out;
    }
}

class Debug {
    public static PrintWriter out;

    public static void printObjects(Object... objects) {
        out.println(Arrays.deepToString(objects));
        out.flush();
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

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

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

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


import java.io.*;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class E {
    //Solution by Sathvik Kuthuru
    public static void main(String[] args) {
        FastReader scan = new FastReader();
        PrintWriter out = new PrintWriter(System.out);
        Task solver = new Task();
        int t = 1;
        for(int tt = 1; tt <= t; tt++) solver.solve(tt, scan, out);
        out.close();
    }

    static class Task {
        int n;
        long[] a;
        long[][] dp;

        public void solve(int testNumber, FastReader scan, PrintWriter out) {
            n = scan.nextInt();
            a = new long[n];
            dp = new long[n][3];
            for(int i = 0; i < n; i++) {
                a[i] = scan.nextLong();
                Arrays.fill(dp[i], -1);
            }
            long ans = Long.MIN_VALUE;
            for(int i = 0; i < 3; i++) ans = Math.max(ans, go(0, i));
            out.println(ans);
        }

        long go(int at, int curr) {
            if(at >= n) return 0;
            if(dp[at][curr] != -1) return dp[at][curr];
            long res = -Long.MAX_VALUE / 20;
            long ans = curr == 1 ? a[at] : -a[at];
            for(int i = curr; i <= 2; i++) res = Math.max(res, ans + go(at + 1, i));
            return dp[at][curr] = res;
        }
    }

    static void shuffle(int[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            int temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static void shuffle(long[] a) {
        Random get = new Random();
        for (int i = 0; i < a.length; i++) {
            int r = get.nextInt(a.length);
            long temp = a[i];
            a[i] = a[r];
            a[r] = temp;
        }
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

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

        public FastReader(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(new File(s)));
        }

        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;
        }
    }

}


//package Jobeel;

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

public class codeforces {
	public static void main(String[] args) throws IOException, InterruptedException {
		InputReader sc=new InputReader(System.in);
		int x=sc.nextInt();
		int [] arr=sc.nextIntArray(x);
		long max=0,sum=0,c=0;
		for(int i=0;i<x;i++) {
			sum+=arr[i];
			c+=arr[i];
			if(c<0) c=0;
			max=Math.max(max, c);
		}
		pw.println((max<<1)-sum);
		pw.flush();
		pw.close();
	}

	static class pair implements Comparable<pair> {
		String name;
		int x, y, z;

		public pair(int x, int y) {
			this.x = x;
			this.y = y;
		}

		public int compareTo(pair o) {
			if (x != o.x)
				return x - o.x;
			return y - o.y;
		}

		public String toString() {
			return x + " " + y;
		}
	}

	static int[] size, arr;
	static long inv = (long) 2e18;
	static long M = (long) 1e9 + 9, P = 999983;
	static HashSet<StringBuilder> set_1;
	static TreeSet<Long> set;

	static int fix(int a, int k) { // turn -% to +%
		return (a % k + k) % k;
	}

	static void solveBruteForece(int index, int mask, int[] arr) {
		if (index == arr.length) {
			long sum = 1;
			for (int i = 0; i < arr.length; i++) {
				if ((mask & 1 << i) != 0)
					sum *= arr[i];

			}
			for (int i = 0; i < arr.length; i++) {
				if (sum % arr[i] != 0)
					return;
			}
			inv = Math.min(inv, sum);
			return;
		}
		solveBruteForece(index + 1, mask | 1 << index, arr);
		solveBruteForece(index + 1, mask, arr);
	}

	public static int find(int i) {
		if (arr[i] == i)
			return i;
		else {
			int result = find(arr[i]);
			arr[i] = result;
			return result;
		}
	}

	public static void union(int u, int v) {
		int root_u = find(u);
		int root_v = find(v);
		if (root_u == root_v)
			return;
		else if (size[root_u] > size[root_v]) {
			size[root_u] += size[root_v];
			arr[root_v] = root_u;
		} else {
			size[root_v] += size[root_u];
			arr[root_u] = root_v;
		}
	}

	static int search(int x, int[] arr) {
		int low = 0, high = arr.length - 1, ans = -1;
		while (low <= high) {
			int mid = (low + high) >> 1;
			if (arr[mid] == x) {
				ans = mid;
				break;
			} else if (arr[mid] > x)
				high = mid - 1;
			else
				low = mid + 1;
		}
		return ans;
	}

	static long gcd(long a, long b) {
		if (b == 0)
			return a;
		return gcd(b, a % b);

	}

	public static long largestDivisor(long n) {
		long divisor = 0;
		long w = n >> 1;
		for (int i = 1; i <= w; i++)
			if (n % i == 0)
				divisor = i;

		return divisor;
	}

	static int min(int x, int y, int z) {
		return Math.min(Math.min(x, y), z);
	}

	static long min(long x, long y, long z) {
		return Math.min(Math.min(x, y), z);
	}

	static int max(int x, int y, int z) {
		return Math.max(Math.max(x, y), z);
	}

	static long max(long x, long y, long z) {
		return Math.max(Math.max(x, y), z);
	}

	static PrintWriter pw = new PrintWriter(System.out);

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

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

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

	}

	static TreeSet<Long> printDivisors(long n) {
		TreeSet<Long> set = new TreeSet<>();
		for (long i = 1; i <= Math.sqrt(n); i++) {
			if (n % i == 0) {
				if (n / i == i)
					set.add(i);

				else {
					set.add(i);
					set.add(n / i);
				}
			}
		}
		return set;
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static class Reader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(s()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
    }

    ///////////////////////////////////////////////////////////////////////////////////////////
    //    RRRRRRRRR            AAA             HHH     HHH     IIIIIIIIIIIII   LLL           //
    //    RR    RRR           AAAAA            HHH     HHH      IIIIIIIIIII    LLL           //
    //    RR   RRR           AAAAAAA           HHH     HHH          III        LLL           //
    //    RR  RRR           AAA   AAA          HHHHHHHHHHH          III        LLL           //
    //    RRRRRR           AAA     AAA         HHHHHHHHHHH          III        LLL           //
    //    RR  RRR         AAAAAAAAAAAAA        HHH     HHH          III        LLL           //
    //    RR    RRR      AAA         AAA       HHH     HHH      IIIIIIIIIII    LLLLLLLLLLLL  //
    //    RR     RRR    AAA           AAA      HHH     HHH     IIIIIIIIIIIII   LLLLLLLLLLLL  //
    ///////////////////////////////////////////////////////////////////////////////////////////
    static int cache[][][];
    static int arr[];
    static int n;
    public static int dp(int pos,int pre,int suf)
    {
        if(pos==n)
        {
            return 0;
        }
        if(cache[pos][pre][suf]!=-1)
        return cache[pos][pre][suf];
        if(suf==1&&pre==0)
        return cache[pos][pre][suf]=-arr[pos]+dp(pos+1,0,1);
        if(suf==1&&pre==1)
        return cache[pos][pre][suf]=Math.max(arr[pos]+dp(pos+1,1,1),-arr[pos]+dp(pos+1,0,1));
        if(suf==0&&pre==1)
        return cache[pos][pre][suf]=Math.max(-arr[pos]+dp(pos+1,1,0),Math.max(-arr[pos]+dp(pos+1,0,1),arr[pos]+dp(pos+1,1,1)));
        if(suf==0&&pre==0)
        return cache[pos][pre][suf]=Math.max(arr[pos]+dp(pos+1,0,0),-arr[pos]+dp(pos+1,0,1));
        return 0;
    }
    public static void main(String[] args)throws IOException
    {
        PrintWriter out= new PrintWriter(System.out);
        Reader sc=new Reader();
        n=sc.i();
        arr=new int[n];for(int i=0;i<n;i++)arr[i]=sc.i();
        cache=new int[n][2][2];for(int i=0;i<n;i++)for(int j=0;j<2;j++)Arrays.fill(cache[i][j],-1);
        System.out.println(Math.max(arr[0]+dp(1,1,1),-arr[0]+dp(1,1,0)));

    }
}


import java.util.*;
import java.io.*;
import java.math.*;
public class Main
{
    static class Reader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public Reader() { this(System.in); }public Reader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String s(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(s()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
    }

    ///////////////////////////////////////////////////////////////////////////////////////////
    //    RRRRRRRRR            AAA             HHH     HHH     IIIIIIIIIIIII   LLL           //
    //    RR    RRR           AAAAA            HHH     HHH      IIIIIIIIIII    LLL           //
    //    RR   RRR           AAAAAAA           HHH     HHH          III        LLL           //
    //    RR  RRR           AAA   AAA          HHHHHHHHHHH          III        LLL           //
    //    RRRRRR           AAA     AAA         HHHHHHHHHHH          III        LLL           //
    //    RR  RRR         AAAAAAAAAAAAA        HHH     HHH          III        LLL           //
    //    RR    RRR      AAA         AAA       HHH     HHH      IIIIIIIIIII    LLLLLLLLLLLL  //
    //    RR     RRR    AAA           AAA      HHH     HHH     IIIIIIIIIIIII   LLLLLLLLLLLL  //
    ///////////////////////////////////////////////////////////////////////////////////////////
    static int cache[][][];
    static int arr[];
    static int n;
    public static int dp(int pos,int pre,int suf)
    {
        if(pos==n)
        {
            if(suf!=1)
            return -2000000000;
            else
            return 0;
        }
        if(cache[pos][pre][suf]!=-1)
        return cache[pos][pre][suf];
        if(suf==1&&pre==0)
        return cache[pos][pre][suf]=-arr[pos]+dp(pos+1,0,1);
        if(suf==1&&pre==1)
        return cache[pos][pre][suf]=Math.max(arr[pos]+dp(pos+1,1,1),-arr[pos]+dp(pos+1,0,1));
        if(suf==0&&pre==1)
        return cache[pos][pre][suf]=Math.max(-arr[pos]+dp(pos+1,1,0),Math.max(-arr[pos]+dp(pos+1,0,1),arr[pos]+dp(pos+1,1,1)));
        if(suf==0&&pre==0)
        return cache[pos][pre][suf]=Math.max(arr[pos]+dp(pos+1,0,0),-arr[pos]+dp(pos+1,0,1));
        return 0;
    }
    public static void main(String[] args)throws IOException
    {
        PrintWriter out= new PrintWriter(System.out);
        Reader sc=new Reader();
        n=sc.i();
        arr=new int[n];for(int i=0;i<n;i++)arr[i]=sc.i();
        cache=new int[n][2][2];for(int i=0;i<n;i++)for(int j=0;j<2;j++)Arrays.fill(cache[i][j],-1);
        System.out.println(Math.max(arr[0]+dp(1,1,1),-arr[0]+dp(1,1,0)));

    }
}


import java.util.Scanner;

public class File1{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int a[] = new int[n];
		for(int i=0;i<n;i++)
			a[i] = in.nextInt();
		int max = 0;
		int temp = 0;
		int sum = 0;
		for(int i=0;i<n;i++){
			temp = temp+a[i];
			if(temp<0) temp = 0;
			if(temp>max) max = temp;
			sum = sum+a[i];
		}
		sum = 2*max - sum;
		System.out.println(sum);
	}
}


// package Practice1.CF33;
import java.util.Scanner;
public class CF033C {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
            sum += arr[i];
        }
        int s1 = maxSubArraySum(arr,n);
        System.out.println(2*s1 - sum);
    }

    public static int maxSubArraySum(int a[], int size) {
        int max_so_far = a[0];
        int curr_max = a[0];

        for (int i = 1; i < size; i++)
        {
            curr_max = Math.max(a[i], curr_max+a[i]);
            max_so_far = Math.max(max_so_far, curr_max);
        }
        return max_so_far;
    }
}


// package Practice1.CF33;
import java.util.Scanner;
public class CF033C {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int n = s.nextInt();
        int[] arr = new int[n];
        long sum = 0;
        for (int i = 0; i < n; i++) {
            arr[i] = s.nextInt();
            sum += arr[i];
        }
        int s1 = maxSubArraySum(arr,n);
        System.out.println(Math.max(2*s1 - sum,-sum));
    }

    public static int maxSubArraySum(int a[], int size) {
        int max_so_far = a[0];
        int curr_max = a[0];

        for (int i = 1; i < size; i++)
        {
            curr_max = Math.max(a[i], curr_max+a[i]);
            max_so_far = Math.max(max_so_far, curr_max);
        }
        return max_so_far;
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class C implements Runnable {

    private StringTokenizer tt = new StringTokenizer("");

    private BufferedReader reader;

    private PrintWriter writer;

    private String nextToken() throws IOException {
        while (!tt.hasMoreTokens()) {
            tt = new StringTokenizer(reader.readLine());
        }
        return tt.nextToken();
    }

    private int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    private void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        int[] dl = new int[n + 1];
        dl[0] = 0;
        for (int i = 0; i < n; i++) {
            dl[i + 1] = dl[i] + a[i];
        }
        int min = 0;
        for (int i = 1; i <= n; i++) {
            min = Math.min(min, dl[i]);
            dl[i] -= 2 * min;
        }

        int[] dr = new int[n + 1];
        dr[n] = 0;
        min = 0;
        for (int i = n - 1; i >= 0; i--) {
            dr[i] = dr[i + 1] + a[i];
        }
        for (int i = n - 1; i >= 0; i--) {
            min = Math.min(min, dr[i]);
            dr[i] -= 2 * min;
        }

        int ans = 0;
        for (int i = 0; i <= n; i++) {
            ans = Math.max(ans, dl[i] + dr[i]);
        }
        writer.println(ans);
    }

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in)); writer = new PrintWriter(System.out);
            //reader = new BufferedReader(new FileReader("input.txt")); writer = new PrintWriter("output.txt");

            solve();
            reader.close();
            writer.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        new Thread(new C()).start();
    }
}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
public class Main {
    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
        }
    class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
        public int read() {

            if (numChars == -1)

                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {

                    numChars = stream.read(buf);

                } catch (IOException e) {

                    throw new InputMismatchException();

                }

                if (numChars <= 0)

                    return -1;
            }
            return buf[curChar++];
        }
        public int readInt() {

            int c = read();

            while (isSpaceChar(c))

            c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
            throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
        public String next() {
            return readString();
        }
    }
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();
        }
        }
    /**
     * @param args
     */
    InputReader in= new InputReader(System.in);
    OutputWriter out = new OutputWriter(System.out);
    StringTokenizer tok;
        public static void main(String[] args) throws IOException
        {
           new Main().run();
        }
        void run() throws IOException
        {
           solve();
           out.flush();
           tok=null;
        }
        void solve() throws IOException{
            /*
             * tha deiksw oti i allilepikalipsi mas einai adiafori:
             * estw xi...xj ta allilepikaliptomena simeia
             * tote ginontai -xi.....-xj apo to  prefix -
             * kai xi...xj apo to suffix -
             * to opoio einai san na ginontai meion ta 1...i-1 kai ta j+1...n
             * opote auto pou kanw einai gia kathe thesi na briskw to kalitero prefix  pou ehei ginei mexri(i kai pio pisw) apo auto to simeio:
             * A[i]=A[i-1]+V[i]  { dil edw to prefix - stamataei toulaxiston mia thesi pio prin}
             * i A[i]=-1...i -V[i]
             * afou ta ehw ipologisei auta ksekinaw apo pisw suffix  kathe fora prsthetw neo stoixeio ka ibriskw to max :)
             */
            int n=in.readInt();
            int[] V=new int[n];
            int[] A=new int[n];
            int sum=0;
            for (int i=0;i<n;++i){
                 V[i]=in.readInt();
                sum+=V[i];
                if (i==0){
                    A[i]=Math.max(V[i],-V[i]);
                }else{
                    A[i]=Math.max(A[i-1]+V[i], -sum);
            } }
            int lsum=0;
            int best=Math.max(sum,-sum);
            for (int i=n-1;i>=0;--i){
                lsum+=V[i];
                if (i==0){
                    best=Math.max(best,-lsum);
                }else{
                best=Math.max(best,-lsum+A[i-1]); //me suffix -
                best=Math.max(best,lsum+A[i-1]); //xwris
            } }
            out.printLine(best);

        }
}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.StringTokenizer;
public class Main {
    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
        }
    class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        public InputReader(InputStream stream) {
            this.stream = stream;
        }
        public int read() {

            if (numChars == -1)

                throw new InputMismatchException();

            if (curChar >= numChars) {

                curChar = 0;

                try {

                    numChars = stream.read(buf);

                } catch (IOException e) {

                    throw new InputMismatchException();

                }

                if (numChars <= 0)

                    return -1;
            }
            return buf[curChar++];
        }
        public int readInt() {

            int c = read();

            while (isSpaceChar(c))

            c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
            throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public long readLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
        public String next() {
            return readString();
        }
    }
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();
        }
        }
    /**
     * @param args
     */
    InputReader in= new InputReader(System.in);
    OutputWriter out = new OutputWriter(System.out);
    StringTokenizer tok;
        public static void main(String[] args) throws IOException
        {
           new Main().run();
        }
        void run() throws IOException
        {
           solve();
           out.flush();
           tok=null;
        }
        void solve() throws IOException{
            /*
             * tha deiksw oti i allilepikalipsi mas einai adiafori:
             * estw xi...xj ta allilepikaliptomena simeia
             * tote ginontai -xi.....-xj apo to  prefix -
             * kai xi...xj apo to suffix -
             * to opoio einai san na ginontai meion ta 1...i-1 kai ta j+1...n
             * opote auto pou kanw einai gia kathe thesi na briskw to kalitero prefix  pou ehei ginei mexri(i kai pio pisw) apo auto to simeio:
             * A[i]=A[i-1]+V[i]  { dil edw to prefix - stamataei toulaxiston mia thesi pio prin}
             * i A[i]=-1...i -V[i]
             * afou ta ehw ipologisei auta ksekinaw apo pisw suffix  kathe fora prsthetw neo stoixeio ka ibriskw to max :)
             */
            int n=in.readInt();
            int[] V=new int[n];
            int[] A=new int[n];
            int sum=0;
            for (int i=0;i<n;++i){
                 V[i]=in.readInt();
                sum+=V[i];
                if (i==0){
                    A[i]=Math.max(V[i],-V[i]);
                }else{
                    A[i]=Math.max(A[i-1]+V[i], -sum);
            } }
            int lsum=0;
            int best=0;
            for (int i=n-1;i>=0;--i){
                lsum+=V[i];
                if (i==0){
                    best=Math.max(best,-lsum);
                }else{
                best=Math.max(best,-lsum+A[i-1]);
            } }
            out.printLine(best);

        }
}