#include <stdio.h>

static int _lcount[500] = {}, _skip_time[500][500] = {}, _min_time[500][501] = {};

static inline int mini(int a, int b) { return a < b ? a : b; }
static void fill_cost(int D, int M, const char t[static M]) {
    int l[500] = {}, lc = 0;
    for(int i = 0 ; i < M ; ++i) if(t[i] == '1') l[lc++] = i;

    _lcount[D] = lc;
    if(lc > 0) _skip_time[D][0] = l[lc-1] - l[0] + 1;
    if(lc > 1) _skip_time[D][lc-1] = 1;

    for(int s = 1, sn = lc-1 ; s < sn ; ++s) {
        const int cnt = lc-s-1; int mintime = 1000;
        for(int i = 0 ; i + cnt < lc ; ++i)
            mintime = mini(mintime, l[i+cnt] - l[i] + 1);
        _skip_time[D][s] = mintime;
    }
}

int main() {
    int N,M,K; scanf("%d %d %d\n", &N,&M,&K);

    for(int i = 0 ; i < N ; ++i) {
        char str[M+1]; scanf("%s\n", str);
        fill_cost(i,M,str);
    }

    for(int i = 0 ; i <= K ; ++i)
        _min_time[0][i] = _skip_time[0][i];
    for(int i = 1 ; i < N ; ++i) {
        for(int j = 0 ; j <= K ; ++j) {
            _min_time[i][j] = _min_time[i-1][j] + _skip_time[i][0];
            for(int s = 1 ; s <= _lcount[i] && s <= j ; ++s)
                _min_time[i][j] = mini(_min_time[i][j], _min_time[i-1][j-s] + _skip_time[i][s]);
        }
    }

    int ans = _min_time[N-1][0]; for(int i = 1 ; i <= K ; ++i) ans = mini(ans, _min_time[N-1][i]);
    printf("%d\n", ans);
    return 0;
}


#include "stdio.h"
const int inf=0x3f3f3f3f;
char clas[505];
int sum[505];
int skip[505][505];
int cost[505][505];
int dp[505];
int MIN(int x,int y)
{
    if(x<y)
        return x;
    else return y;
}
int MAX(int x,int y)
{
    if(x>y)
        return x;
    else return y;
}
int main()
{
    int n,m,k,j,i,p,r,l,mi;
    scanf("%d%d%d",&n,&m,&k);
    for(i=1;i<=n;i++)
    {
        scanf("%s",clas+1);
        for(j=1;j<=m;j++)
        {
            if(clas[j]=='1')
                {
                    sum[i]++;
                    skip[i][sum[i]]=j;
                }
        }

        for(p=0;p<=sum[i]-1;p++)
        {
            mi=inf;
            for(l=0;l<=sum[i]-1;l++)
            {
                if(p-l<0)
                    break;
                r=p-l;
                mi=MIN(mi,skip[i][sum[i]-r]-skip[i][l+1]+1);
            }
            cost[i][p]=m-mi;
        }
        cost[i][sum[i]]=m;
    }
    for(i=1;i<=n;i++)
        for(j=k;j>=0;j--)
            for(p=0;p<=MIN(sum[i],j);p++)
        {
            dp[j]=MAX(dp[j],dp[j-p]+cost[i][p]);
        }
    printf("%d\n",n*m-dp[k]);
    return 0;
}


#include "stdio.h"

int dp[600][600];
int time_spent[600][600];
char a[600];

int N, M, K;

#define min(a, b) (((a)<(b))?(a):(b))
#define max(a, b) (((a)>(b))?(a):(b))

int f(int i, int k) {
  if (i == N) return 0;
  if (dp[i][k] != -1) return dp[i][k];
  int skipped_lessons;
  int result = M*N;
  for (skipped_lessons = 0; skipped_lessons < k+1; ++skipped_lessons) {
      result = min(result,
        time_spent[i][skipped_lessons] + f(i+1, k-skipped_lessons));
  }
  dp[i][k] = result;
  return result;
}

int main() {
  int i, j;
  for (i = 0; i < 600; ++i)
    for (j = 0; j < 600; ++j)
      dp[i][j] = -1;

  scanf("%d %d %d", &N, &M, &K);

  for (i = 0; i < N; ++i) {
    scanf("%s", &a);
    int skip_from_start[600];
    int skip_from_end[600];
    int total_lessons = 0;
    int spent;
    for (j = 0; j < 600; ++j) {
        if (j < M && a[j] == '1') ++total_lessons;
        skip_from_start[j] = 0;
        skip_from_end[j] = 0;
        time_spent[i][j] = 0;
    }

    int spent_from_start = 0;
    int spent_from_end = 0;
    for (j = 0; j < M; ++j) {
        if (a[j] == '1') ++spent_from_start;
        if (a[M-j-1] == '1') ++spent_from_end;
        skip_from_start[spent_from_start] = j+1;
        skip_from_end[spent_from_end] = j+1;
    }

    /*for (j = 0; j < M; ++j) {
        printf("%d ", skip_from_start[j]);
    }
    printf(": ");
    for (j = 0; j < M; ++j) {
        printf("%d ", skip_from_end[j]);
    }
    printf("\n");*/

    int skipped_lessons;
    for (skipped_lessons = 0; skipped_lessons < min(total_lessons, K+1);  ++skipped_lessons) {
        int max_skip = 0;
        for (j = 0; j < skipped_lessons+1; ++j)
            max_skip = max(max_skip,
                skip_from_start[j] + skip_from_end[skipped_lessons-j]);
        time_spent[i][skipped_lessons] = M - max_skip;
        //printf("%d->%d : %d", i, skipped_lessons, time_spent[i][skipped_lessons]);
        //printf("\n");
    }
  }

  printf("%d\n", f(0, K));
  return 0;
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D946 solver = new D946();
        solver.solve(1, in, out);
        out.close();
    }

    static class D946 {
        int N;
        int M;
        int K;
        int oo = 123456789;

        int[] cost(char[] row) {
            int[] cs = new int[M + 1];
            for (int i = 1; i <= M; i++)
                cs[i] = cs[i - 1] + (row[i - 1] - '0');
            int[] ret = new int[K + 1];
            Arrays.fill(ret, M);
            for (int i = 1; i <= M; i++) {
                for (int j = i - 1; j <= M; j++) {
                    int ct = cs[j] - cs[i - 1];
                    if (cs[M] - ct > K) continue;
                    int h = j - i + 1;
                    ret[cs[M] - ct] = Math.min(ret[cs[M] - ct], h);
                }
            }
            return ret;
        }

        public void solve(int testNumber, FastScanner s, PrintWriter out) {

            N = s.nextInt();
            M = s.nextInt();
            K = s.nextInt();

            int[] memo = new int[K + 1];
            for (int d = 0; d < N; d++) {
                char[] row = s.next().toCharArray();
                int[] cost = cost(row);
//            System.out.println(Arrays.toString(row));
//            System.out.println(Arrays.toString(cost));
                for (int p = K; p >= 0; p--) {
                    int best = oo;
                    for (int v = p; v >= 0; v--) {
                        best = Math.min(best, memo[v] + cost[p - v]);
                    }
                    memo[p] = best;
                }
            }

            out.println(memo[K]);

        }

    }

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

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

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

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

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

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D946 solver = new D946();
        solver.solve(1, in, out);
        out.close();
    }

    static class D946 {
        int N;
        int M;
        int K;
        int oo = 123456789;

        int[] cost(char[] row) {
            int[] cs = new int[M + 1];
            for (int i = 1; i <= M; i++)
                cs[i] = cs[i - 1] + (row[i - 1] - '0');
            int[] ret = new int[K + 1];
            Arrays.fill(ret, M);
            for (int i = 1; i < M; i++) {
                for (int j = i; j <= M; j++) {
                    int ct = cs[j] - cs[i - 1];
                    if (cs[M] - ct > K) continue;
                    int h = j - i + 1;
                    ret[cs[M] - ct] = Math.min(ret[cs[M] - ct], h);
                }
            }
            return ret;
        }

        public void solve(int testNumber, FastScanner s, PrintWriter out) {

            N = s.nextInt();
            M = s.nextInt();
            K = s.nextInt();

            int[] memo = new int[K + 1];
            for (int d = 0; d < N; d++) {
                char[] row = s.next().toCharArray();
                int[] cost = cost(row);
                for (int p = K; p >= 0; p--) {
                    int best = oo;
                    for (int v = p; v >= 0; v--) {
                        best = Math.min(best, memo[v] + cost[p - v]);
                    }
                    memo[p] = best;
                }
            }

            out.println(memo[K]);

        }

    }

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

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

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

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

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

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

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
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;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        D946 solver = new D946();
        solver.solve(1, in, out);
        out.close();
    }

    static class D946 {
        int N;
        int M;
        int K;
        int oo = 123456789;

        int[] cost(char[] row) {
            int[] cs = new int[M + 1];
            for (int i = 1; i <= M; i++)
                cs[i] = cs[i - 1] + (row[i - 1] - '0');
            int[] ret = new int[K + 1];
            Arrays.fill(ret, M);
            for (int i = 1; i < M; i++) {
                for (int j = i - 1; j <= M; j++) {
                    int ct = cs[j] - cs[i - 1];
                    if (cs[M] - ct > K) continue;
                    int h = j - i + 1;
                    ret[cs[M] - ct] = Math.min(ret[cs[M] - ct], h);
                }
            }
            return ret;
        }

        public void solve(int testNumber, FastScanner s, PrintWriter out) {

            N = s.nextInt();
            M = s.nextInt();
            K = s.nextInt();

            int[] memo = new int[K + 1];
            for (int d = 0; d < N; d++) {
                char[] row = s.next().toCharArray();
                int[] cost = cost(row);
                for (int p = K; p >= 0; p--) {
                    int best = oo;
                    for (int v = p; v >= 0; v--) {
                        best = Math.min(best, memo[v] + cost[p - v]);
                    }
                    memo[p] = best;
                }
            }

            out.println(memo[K]);

        }

    }

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

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

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

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

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

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

    }
}


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

public class Solution
{
	public static int[] findMin(String a, int n,int k){
		  int[] dp = new int[k+1];
		  char[] cc = a.toCharArray();
			int n1 = 0;
			for (int i = 0; i < n; i++)
				if (cc[i] == '1')
					n1++;

			if (n1 == 0)
				return dp;
			int[] ii = new int[n1];
			n1 = 0;
			for (int i = 0; i < n; i++)
				if (cc[i] == '1')
					ii[n1++] = i;
			int span = ii[n1 - 1] - ii[0] + 1;

			for (int l = 0; l <= Math.min(k,ii.length-1); l++)
				dp[l] = span;

			for (int i = 0; i < n1; i++)
				for (int j = i; j < n1; j++) {
					int l = i + n1 - 1 - j;
					if (l <= k) {
						int span_ = ii[j] - ii[i] + 1;
						dp[l] = Math.min(dp[l], span_);
					}
				}
			return dp;
	     }

	    public static int findMin(int[][] mh, int n, int m, int k){
	        int[] dp = new int[k+1];

	        for(int i=0; i<=k; i++)
	         dp[i] = mh[1][i];

	         for(int i= 2; i<=n; i++){

	           for(int j=k;j>=0; j--){
	               dp[j]+=mh[i][0];
	               for(int y=1; y<=j; y++)
	                dp[j] = Math.min(dp[j],mh[i][y]+dp[j-y]);
	           }
	         }

	        return dp[k];
	    }

		public static void main (String[] args) throws java.lang.Exception
		{
		    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		    PrintWriter out = new PrintWriter(System.out);
		    StringTokenizer st = new StringTokenizer(br.readLine());

		    int n = Integer.parseInt(st.nextToken());
		    int m = Integer.parseInt(st.nextToken());
		    int k = Integer.parseInt(st.nextToken());

		    int[][] mh = new int[n+1][k+1];

		    for(int i=0; i<n; i++)
		     mh[i+1] = findMin(br.readLine(),m,k);

		      out.println(findMin(mh,n,m,k));
	            out.close();
		}
}


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

public class Solution
{
	public static int[] findMin(String a, int n,int k){
		  int[] dp = new int[k+1];
		  char[] cc = a.toCharArray();
			int n1 = 0;
			for (int i = 0; i < n; i++)
				if (cc[i] == '1')
					n1++;

			if (n1 == 0)
				return dp;
			int[] ii = new int[n1];
			n1 = 0;
			for (int i = 0; i < n; i++)
				if (cc[i] == '1')
					ii[n1++] = i;
			int span = ii[n1 - 1] - ii[0] + 1;

			for (int l = 0; l <= k && l < ii.length; l++)
				dp[l] = span;

			for (int i = 0; i < n1; i++)
				for (int j = i; j < n1; j++) {
					int l = i + n1 - 1 - j;
					if (l <= k) {
						int span_ = ii[j] - ii[i] + 1;
						dp[l] = Math.min(dp[l], span_);
					}
				}
			//System.out.println(Arrays.toString(dp));
			return dp;
	     }

	    public static int findMin(int[][] mh, int n, int m, int k){
	        int[][] dp = new int[n+1][k+1];

	        for(int i=0; i<=k; i++)
	         dp[1][i] = mh[1][i];

	         for(int i= 2; i<=n; i++){
	             dp[i][0] = dp[i-1][0]+mh[i][0];

	           for(int j=1;j<=k; j++){
	               dp[i][j] = Integer.MAX_VALUE;
	               for(int y=0; y<=j; y++)
	                dp[i][j] = Math.min(dp[i][j],mh[i][y]+dp[i-1][j-y]);
	           }
	         }

	        return dp[n][k];
	    }

		public static void main (String[] args) throws java.lang.Exception
		{
		    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		    PrintWriter out = new PrintWriter(System.out);
		    StringTokenizer st = new StringTokenizer(br.readLine());

		    int n = Integer.parseInt(st.nextToken());
		    int m = Integer.parseInt(st.nextToken());
		    int k = Integer.parseInt(st.nextToken());

		    int[][] mh = new int[n+1][k+1];

		    for(int i=0; i<n; i++)
		     mh[i+1] = findMin(br.readLine(),m,k);

		      out.println(findMin(mh,n,m,k));
	            out.close();
		}
}


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

public class Solution
{
	public static int[] findMin(String a, int k){
	         int low =0, high = a.length()-1;
	         int[] swap = new int[k+1];
	         int j = 0;

	               while(low <= high && a.charAt(low) == '0') low++;
	               if(low > high) return swap;
	                while(high >= low && a.charAt(high) == '0') high--;

	             swap[0] = (high-low+1);

	          while(low < high && j<k){
	              int itr = low+1;
	              while(itr < high && a.charAt(itr) == '0') itr++;

	              int min = itr;
	              itr = high-1;

	               while(itr > low && a.charAt(itr) == '0') itr--;

	               if(high-min <= itr-low)  low = min;
	               else high = itr;

	               swap[++j] = (high-low+1);

	          }
	         return swap;
	     }

	    public static int findMin(int[][] mh, int n, int m, int k){
	        int[][] dp = new int[n+1][k+1];

	        for(int i=0; i<=k; i++)
	         dp[1][i] = mh[1][i];

	         for(int i= 2; i<=n; i++){
	             dp[i][0] = dp[i-1][0]+mh[i][0];

	           for(int j=1;j<=k; j++){
	               dp[i][j] = Integer.MAX_VALUE;
	               for(int y=0; y<=j; y++)
	                dp[i][j] = Math.min(dp[i][j],mh[i][y]+dp[i-1][j-y]);
	           }
	         }
		       /* for(int i=1; i<=n; i++)
					 System.out.println(Arrays.toString(dp[i])); */
	        return dp[n][k];
	    }

		public static void main (String[] args) throws java.lang.Exception
		{
		    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		    PrintWriter out = new PrintWriter(System.out);
		    StringTokenizer st = new StringTokenizer(br.readLine());

		    int n = Integer.parseInt(st.nextToken());
		    int m = Integer.parseInt(st.nextToken());
		    int k = Integer.parseInt(st.nextToken());

		    int[][] mh = new int[n+1][k+1];

		    for(int i=0; i<n; i++)
		     mh[i+1] = findMin(br.readLine(),k);

		      out.println(findMin(mh,n,m,k));
	            out.close();
		}
}


 /* dp[i][j] = Math.min(dp[i][j],((y=0, -> j) min[i][y]+dp[i-1][j-y)]  */
import java.util.*;
import java.lang.*;
import java.io.*;

public class Solution
{
	public static int[] findMin(String a, int n,int k){
		  int[] dp = new int[k+1];
		  char[] cc = a.toCharArray();
			int n1 = 0;
			for (int i = 0; i < n; i++)
				if (cc[i] == '1')
					n1++;

			if (n1 == 0)
				return dp;
			int[] ii = new int[n1];
			n1 = 0;
			for (int i = 0; i < n; i++)
				if (cc[i] == '1')
					ii[n1++] = i;
			int span = ii[n1 - 1] - ii[0] + 1;

			for (int l = 0; l <= Math.min(k,ii.length-1); l++)
				dp[l] = span;

			for (int i = 0; i < n1; i++)
				for (int j = i; j < n1; j++) {
					int l = i + n1 - 1 - j;
					if (l <= k) {
						int span_ = ii[j] - ii[i] + 1;
						dp[l] = Math.min(dp[l], span_);
					}
				}
			return dp;
	     }

	    public static int findMin(int[][] mh, int n, int m, int k){
	        int[][] dp = new int[n+1][k+1];

	        for(int i=0; i<=k; i++)
	         dp[1][i] = mh[1][i];

	         for(int i= 2; i<=n; i++){
	             dp[i][0] = dp[i-1][0]+mh[i][0];

	           for(int j=1;j<=k; j++){
	               dp[i][j] = Integer.MAX_VALUE;
	               for(int y=0; y<=j; y++)
	                dp[i][j] = Math.min(dp[i][j],mh[i][y]+dp[i-1][j-y]);
	           }
	         }

	        return dp[n][k];
	    }

		public static void main (String[] args) throws java.lang.Exception
		{
		    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		    PrintWriter out = new PrintWriter(System.out);
		    StringTokenizer st = new StringTokenizer(br.readLine());

		    int n = Integer.parseInt(st.nextToken());
		    int m = Integer.parseInt(st.nextToken());
		    int k = Integer.parseInt(st.nextToken());

		    int[][] mh = new int[n+1][k+1];

		    for(int i=0; i<n; i++)
		     mh[i+1] = findMin(br.readLine(),m,k);

		      out.println(findMin(mh,n,m,k));
	            out.close();
		}
}


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

public class Solution
{
	public static int[] findMin(String a, int n,int k){
		  int[] dp = new int[k+1];
		  char[] cc = a.toCharArray();
			int n1 = 0;
			for (int i = 0; i < n; i++)
				if (cc[i] == '1')
					n1++;

			if (n1 == 0)
				return dp;
			int[] ii = new int[n1];
			n1 = 0;
			for (int i = 0; i < n; i++)
				if (cc[i] == '1')
					ii[n1++] = i;
			int span = ii[n1 - 1] - ii[0] + 1;
			for (int l = 0; l <= k; l++)
				dp[l] = span;
			for (int i = 0; i < n1; i++)
				for (int j = i; j < n1; j++) {
					int l = i + n1 - 1 - j;
					if (l <= k) {
						int span_ = ii[j] - ii[i] + 1;
						dp[l] = Math.min(dp[l], span_);
					}
				}
			return dp;
	     }

	    public static int findMin(int[][] mh, int n, int m, int k){
	        int[][] dp = new int[n+1][k+1];

	        for(int i=0; i<=k; i++)
	         dp[1][i] = mh[1][i];

	         for(int i= 2; i<=n; i++){
	             dp[i][0] = dp[i-1][0]+mh[i][0];

	           for(int j=1;j<=k; j++){
	               dp[i][j] = Integer.MAX_VALUE;
	               for(int y=0; y<=j; y++)
	                dp[i][j] = Math.min(dp[i][j],mh[i][y]+dp[i-1][j-y]);
	           }
	         }
		       /* for(int i=1; i<=n; i++)
					 System.out.println(Arrays.toString(dp[i])); */
	        return dp[n][k];
	    }

		public static void main (String[] args) throws java.lang.Exception
		{
		    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		    PrintWriter out = new PrintWriter(System.out);
		    StringTokenizer st = new StringTokenizer(br.readLine());

		    int n = Integer.parseInt(st.nextToken());
		    int m = Integer.parseInt(st.nextToken());
		    int k = Integer.parseInt(st.nextToken());

		    int[][] mh = new int[n+1][k+1];

		    for(int i=0; i<n; i++)
		     mh[i+1] = findMin(br.readLine(),m,k);

		      out.println(findMin(mh,n,m,k));
	            out.close();
		}
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  ll ps[maxn];
  ll dp[maxn][2];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0,sa=0;
    ps[0]=0;
    for(int i=1;i<=n;i++)cin>>a[i],ps[i]=ps[i-1]+a[i],s+=a[i],sa+=abs(a[i]);
    if(n==1){
      cout<<a[1]<<endl;
    }
    ll mi=a[1],ma=a[1];
    for(int i=2;i<=n;i++)mi=min(mi,a[i]),ma=max(ma,a[i]);
    ll mia=abs(a[1]),maa=abs(a[1]);
    for(int i=2;i<=n;i++)mia=min(mia,abs(a[i])),maa=max(maa,abs(a[i]));
    ll r;
    r=max(abs(mi*2-s),abs(ma*2-s));
    r=max(r,abs(2*mia-sa));
    r=max(r,abs(2*maa-sa));
    cout<<r<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  ll ps[maxn];
  ll dp[maxn][2];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0,sa=0;
    ps[0]=0;
    for(int i=1;i<=n;i++)cin>>a[i],ps[i]=ps[i-1]+a[i],s+=a[i],sa+=abs(a[i]);
    if(n==1){
      cout<<a[1]<<endl;
      return 0;
    }
    int mii=1,mai=1;
    for(int i=2;i<=n;i++){
      if(a[i]<a[mii])mii=i;
      if(a[i]>a[mai])mai=i;
    }
    ll r=0,r2=0;
    if(a[mii]*a[mai]<=0){
      r=r2=sa;
    }else{
      r=a[mai]-a[mii];
      r2=a[mai]-a[mii];
      for(int i=1;i<=n;i++){
        if(i!=mii&&i!=mai){
          if(a[i]<0)r-=a[i],r2+=a[i];
          else r+=a[i],r2-=a[i];
        }
      }
    }
    cout<<max(abs(r),abs(r2))<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  ll ps[maxn];
  ll dp[maxn][2];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0,sa=0;
    ps[0]=0;
    for(int i=1;i<=n;i++)cin>>a[i],ps[i]=ps[i-1]+a[i],s+=a[i],sa+=abs(a[i]);
    if(n==1){
      cout<<a[1]<<endl;
      return 0;
    }
    ll mii=1,mai=1;
    for(int i=2;i<=n;i++){
      if(a[i]<a[mii])mii=i;
      if(a[i]>a[mai])mai=i;
    }
    ll rmi=a[mai]-a[mii];
    for(int i=1;i<=n;i++){
      if(i!=mii&&i!=mai){
        if(a[i]*a[mai]<0)rmi-=a[i];
        else rmi+=a[i];
      }
    }
    ll rma=a[mii]-a[mai];
    for(int i=1;i<=n;i++){
      if(i!=mii&&i!=mai){
        if(a[i]*a[mii]<0)rma-=a[i];
        else rma+=a[i];
      }
    }
    cout<<max(abs(rmi),abs(rma))<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0,sa=0;
    for(int i=1;i<=n;i++)cin>>a[i],s+=a[i],sa+=abs(a[i]);
    if(n==1){
      cout<<a[1]<<endl;
    }
    ll mi=a[1],ma=a[1];
    for(int i=2;i<=n;i++)mi=min(mi,a[i]),ma=max(ma,a[i]);
    ll r=max(abs(mi*2-s),abs(ma*2-s));
    if(mi*ma<0){
      r=max(r,sa);
    }
    cout<<r<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0;
    for(int i=1;i<=n;i++)cin>>a[i],s+=a[i];
    ll mi=a[1],ma=a[1];
    for(int i=2;i<=n;i++)mi=min(mi,a[i]),ma=max(ma,a[i]);
    cout<<max(abs(mi*2-s),abs(ma*2-s))<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  ll ps[maxn];
  ll dp[maxn][2];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0,sa=0;
    ps[0]=0;
    for(int i=1;i<=n;i++)cin>>a[i],ps[i]=ps[i-1]+a[i],s+=a[i],sa+=abs(a[i]);
    if(n==1){
      cout<<a[1]<<endl;
    }
    ll mi=a[1],ma=a[1];
    for(int i=2;i<=n;i++)mi=min(mi,a[i]),ma=max(ma,a[i]);
    ll mia=abs(a[1]),maa=abs(a[1]);
    for(int i=2;i<=n;i++)mia=min(mia,abs(a[i])),maa=max(maa,abs(a[i]));
    ll r;
    if(mi*ma<=0){
      r=sa;
    }else{
      r=max(abs(mi*2-s),abs(ma*2-s));
      r=max(r,abs(2*mia-sa));
    }
    cout<<r<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0;
    for(int i=1;i<=n;i++)cin>>a[i],s+=a[i];
    if(n==1){
      cout<<a[1]<<endl;
      return 0;
    }
    ll mi=a[1],ma=a[1];
    for(int i=2;i<=n;i++)mi=min(mi,a[i]),ma=max(ma,a[i]);
    cout<<max(abs(mi*2-s),abs(ma*2-s))<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0,sa=0;
    for(int i=1;i<=n;i++)cin>>a[i],s+=a[i],sa+=abs(a[i]);
    if(n==1){
      cout<<a[1]<<endl;
    }
    ll mi=a[1],ma=a[1];
    for(int i=2;i<=n;i++)mi=min(mi,a[i]),ma=max(ma,a[i]);
    ll r=max(abs(mi*2-s),abs(ma*2-s));
    if(mi*ma<=0){
      r=max(r,sa);
    }
    cout<<r<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  ll ps[maxn];
  ll dp[maxn][2];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0,sa=0;
    ps[0]=0;
    for(int i=1;i<=n;i++)cin>>a[i],ps[i]=ps[i-1]+a[i],s+=a[i],sa+=abs(a[i]);
    if(n==1){
      cout<<a[1]<<endl;
      return 0;
    }
    ll mii=1,mai=1;
    for(int i=2;i<=n;i++){
      if(a[i]<a[mii])mii=i;
      if(a[i]>a[mai])mai=i;
    }
    ll r=a[mai]-a[mii];
    ll r2=a[mai]-a[mii];
    for(int i=1;i<=n;i++){
      if(i!=mii&&i!=mai){
        if(a[i]<0)r-=a[i],r2+=a[i];
        else r+=a[i],r2-=a[i];
      }
    }
    cout<<max(abs(r),abs(r2))<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  ll ps[maxn];
  ll dp[maxn][2];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0,sa=0;
    ps[0]=0;
    for(int i=1;i<=n;i++)cin>>a[i],ps[i]=ps[i-1]+a[i],s+=a[i],sa+=abs(a[i]);
    if(n==1){
      cout<<a[1]<<endl;
      return 0;
    }
    ll mii=1,mai=1;
    for(int i=2;i<=n;i++){
      if(a[i]<a[mii])mii=i;
      if(a[i]>a[mai])mai=i;
    }
    ll rmi=a[mai]-a[mii];
    for(int i=1;i<=n;i++){
      if(i!=mii&&i!=mai){
        if(a[i]*a[mai]<0)rmi-=a[i];
        else rmi+=a[i];
      }
    }
    ll rma=a[mii]-a[mai];
    for(int i=1;i<=n;i++){
      if(i!=mii&&i!=mai){
        if(a[i]*a[mai]<0)rma-=a[i];
        else rma+=a[i];
      }
    }
    cout<<max(abs(rmi),abs(rma))<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  ll ps[maxn];
  ll dp[maxn][2];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0,sa=0;
    ps[0]=0;
    for(int i=1;i<=n;i++)cin>>a[i],ps[i]=ps[i-1]+a[i],s+=a[i],sa+=abs(a[i]);
    if(n==1){
      cout<<a[1]<<endl;
    }
    ll mii=1,mai=1;
    for(int i=2;i<=n;i++){
      if(a[i]<a[mii])mii=i;
      if(a[i]>a[mai])mai=i;
    }
    ll rmi=a[mai]-a[mii];
    for(int i=1;i<=n;i++){
      if(i!=mii&&i!=mai){
        if(a[i]*a[mai]<0)rmi-=a[i];
        else rmi+=a[i];
      }
    }
    ll rma=a[mii]-a[mai];
    for(int i=1;i<=n;i++){
      if(i!=mii&&i!=mai){
        if(a[i]*a[mai]<0)rma-=a[i];
        else rma+=a[i];
      }
    }
    cout<<max(abs(rmi),abs(rma))<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#pragma GCC optimize("O3")
#ifdef ONLINE_JUDGE
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#endif
#pragma GCC optimize("unroll-loops")
#pragma comment(linker, "/stack:200000000")
#include <bits/stdc++.h>
#include <type_traits>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
template<typename Key=int,typename Mapped=__gnu_pbds::null_type,typename Cmp_Fn=std::less<Key>,typename Tag=__gnu_pbds::rb_tree_tag,template<typename Const_Node_Iterator,typename Node_Iterator,typename Cmp_Fn_,typename Allocator_>class Node_Update=__gnu_pbds::tree_order_statistics_node_update,typename Allocator=std::allocator<char>>class ordered_set_t:__gnu_pbds::tree<Key,Mapped,Cmp_Fn,Tag,Node_Update,Allocator>{};const int GRANDOM=std::chrono::high_resolution_clock::now().time_since_epoch().count();struct ghash{int operator()(int x){return std::hash<int>{}(x^GRANDOM);}};template<typename KeyType>class hash_table_t:__gnu_pbds::gp_hash_table<KeyType,int,ghash>{};namespace vh{template<class T>void _R(T&x){std::cin>>x;}inline void _R(int&x){scanf("%d",&x);}inline void _R(int64_t&x){scanf("%" SCNd64,&x);}inline void _R(double&x){scanf("%lf",&x);}inline void _R(char&x){scanf(" %c",&x);}inline void _R(char*x){scanf("%s",x);}inline void R(){}template<class T,class... U>inline void R(T&head,U&... tail){_R(head);R(tail...);}template<class T>void _W(const T&x){cout<<x;}inline void _W(const int&x){printf("%d",x);}inline void _W(const int64_t&x){printf("%" PRId64,x);}inline void _W(const double&x){printf("%.16f",x);}inline void _W(const char&x){putchar(x);}inline void _W(const char*x){printf("%s",x);}template<class T>inline void _W(const vector<T>&x){for(auto i=x.begin();i!=x.end();_W(*i++))if(i!=x.cbegin())putchar(' ');}inline void W(){}template<class T,class... U>inline void W(const T&head,const U&... tail){_W(head);if(sizeof...(tail))putchar(' '),W(tail...);}template<class T,class... U>inline void WL(const T&head,const U&... tail){_W(head);putchar(sizeof...(tail)? ' ':'\n');W(tail...);}};
#define prec setprecision
namespace vh{typedef long long ll;typedef unsigned long long llu;template<typename T>T gcd(T m,T n){while(n){T t=m%n;m=n;n=t;};return m;}template<typename T>T exgcd(T a,T b,T&sa,T&ta){T q,r,sb=0,tb=1,sc,tc;sa=1,ta=0;if(b)do q=a/b,r=a-q*b,a=b,b=r,sc=sa-q*sb,sa=sb,sb=sc,tc=ta-q*tb,ta=tb,tb=tc;while(b);return a;}template<typename T>T mul_inv(T a,T b){T t1=a,t2=b,t3;T v1=1,v2=0,v3;T x;while(t2!=1)x=t1/t2,t3=t1-x*t2,v3=v1-x*v2,t1=t2,t2=t3,v1=v2,v2=v3;return(v2+b)%b;}template<typename T>T powmod(T a,T b,T MOD){if(b<0)return 0;T rv=1;while(b)(b%2)&&(rv=(rv*a)%MOD),a=a*a%MOD,b/=2;return rv;}template<ll n>struct BitSize{enum{Size=BitSize<n/2>::Size+1};};template<>struct BitSize<0>{enum{Size=1};};template<>struct BitSize<1>{enum{Size=1};};
#define BITSIZE(n) (BitSize<n>::Size)
#define BITMAX(n) (BitSize<n>::Size - 1)
#define DEBUG !defined(ONLINE_JUDGE)
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x), end(x)
template<typename TH>void _dbg(const char*sdbg,TH h){cerr<<sdbg<<"="<<h<<"\n";}template<typename TH,typename... TA>void _dbg(const char*sdbg,TH h,TA... t){while(*sdbg!=',')cerr<<*sdbg++;cerr<<"="<<h<<",";_dbg(sdbg+1,t...);}
#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; for(auto itt: x) cerr <<*itt <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define cerr if(0)cout
#endif
}namespace vh{template<typename T>int min_rotation(vector<T>s){int a=0,N=s.size();for(int b=0;b<N;b++)for(int i=0;i<N;i++){if(a+i==b||s[(a+i)%N]<s[(b+i)%N]){b+=max(0,i-1);break;}if(s[(a+i)%N]>s[(b+i)%N]){a=b;break;}}return a;}}namespace vh{};
namespace vh{
  const int maxn=500500;
  int n;
  ll a[maxn];
  ll ps[maxn];
  ll dp[maxn][2];
  int main(){
    srand(GRANDOM);
    cin>>n;
    ll s=0,sa=0;
    ps[0]=0;
    for(int i=1;i<=n;i++)cin>>a[i],ps[i]=ps[i-1]+a[i],s+=a[i],sa+=abs(a[i]);
    if(n==1){
      cout<<a[1]<<endl;
      return 0;
    }
    if(n==2){
      cout<<abs(a[1]-a[2])<<endl;
      return 0;
    }
    ll mii=1,mai=1;
    for(int i=2;i<=n;i++){
      if(a[i]<a[mii])mii=i;
      if(a[i]>a[mai])mai=i;
    }
    ll r=0,r2=0;
    if(a[mii]*a[mai]<=0){
      r=r2=sa;
    }else{
      r=a[mai]-a[mii];
      r2=a[mai]-a[mii];
      for(int i=1;i<=n;i++){
        if(i!=mii&&i!=mai){
          if(a[i]<0)r-=a[i],r2+=a[i];
          else r+=a[i],r2-=a[i];
        }
      }
    }
    cout<<max(abs(r),abs(r2))<<endl;
    return 0;
  }
};
int main(int argc,char*argv[]){
  std::cin.sync_with_stdio(false);std::cin.tie(nullptr);
  return vh::main();
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll mins = -1;
	ll sum = 0;
	for(int i = 0; i < n; i++) {
		ll elem;
		cin >> elem;
		if(elem < 0) elem *= -1;
		if(elem < mins || mins == -1) mins = elem;
		sum += elem;
	}
	mins *= 2;
	cout << sum - mins << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll mins = -1;
	ll sum = 0;
	bool neg = true;
	bool pos = true;
	if(n == 1) {
		ll tmp;
		cin >> tmp;
		cout << tmp << endl;
		return 0;
	}
	for(int i = 0; i < n; i++) {
		ll elem;
		cin >> elem;
		if(elem < 0) {
			elem *= -1;
			pos = false;
		} else if(elem > 0) neg = false;
		if(elem < mins || mins == -1) mins = elem;
		sum += elem;
	}
	if(neg || pos) mins *= 2;
	else mins = 0;
	cout << sum - mins << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	if(n == 1) {
	    ll tmp;
	    cin >> tmp;
	    cout << tmp << endl;
	}
	ll mins = -1;
	ll sum = 0;
	bool neg = false;
	bool pos = false;
	for(int i = 0; i < n; i++) {
		ll elem;
		cin >> elem;
		if(elem < 0) {
			elem *= -1;
			neg = true;
		} else pos = true;
		if(elem < mins || mins == -1) mins = elem;
		sum += elem;
	}
	if(neg && pos) mins = 0;
	else mins *= 2;
	cout << sum - mins << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll mins = -1;
	ll sum = 0;
	bool neg = true;
	bool pos = true;
	for(int i = 0; i < n; i++) {
		ll elem;
		cin >> elem;
		if(elem <= 0) {
			elem *= -1;
			pos = false;
		}
		if(elem >= 0) neg = false;
		if(elem < mins || mins == -1) mins = elem;
		sum += elem;
	}
	if(neg || pos) mins *= 2;
	else mins = 0;
	cout << sum - mins << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll mins = -1;
	ll sum = 0;
	bool neg = true;
	bool pos = true;
	for(int i = 0; i < n; i++) {
		ll elem;
		cin >> elem;
		if(elem <= 0) {
			elem *= -1;
			pos = false;
		}
		if(elem >= 0) neg = false;
		if(elem < mins || mins == -1) mins = elem;
		sum += elem;
	}
	if(n == 1) {
		cout << sum << endl;
		return 0;
	}
	if(neg || pos) mins *= 2;
	else mins = 0;
	cout << sum - mins << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll mins = -1;
	ll sum = 0;
	bool neg = false;
	bool pos = false;
	for(int i = 0; i < n; i++) {
		ll elem;
		cin >> elem;
		if(elem < 0) {
			elem *= -1;
			neg = true;
		} else if(elem > 0) pos = true;
		if(elem < mins || mins == -1) mins = elem;
		sum += elem;
	}
	if(neg && pos) mins = 0;
	else mins *= 2;
	cout << sum - mins << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	ll n;
	cin >> n;
	ll mins = -1;
	ll sum = 0;
	bool neg = true;
	bool pos = true;
	for(ll i = 0; i < n; i++) {
		ll elem;
		cin >> elem;
		if(elem < 0) {
			elem *= -1;
			pos = false;
		} else if(elem > 0) neg = false;
		if(elem < mins || mins == -1) mins = elem;
		sum += elem;
	}
	if(neg || pos) mins *= 2;
	else mins = 0;
	cout << sum - mins << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll mins = -1;
	ll sum = 0;
	bool neg = true;
	bool pos = true;
	if(n == 1) {
		ll tmp;
		cin >> tmp;
		cout << tmp << endl;
		return 0;
	}
	for(int i = 0; i < n; i++) {
		ll elem;
		cin >> elem;
		if(elem <= 0) {
			elem *= -1;
			pos = false;
		}
		if(elem >= 0) neg = false;
		if(elem < mins || mins == -1) mins = elem;
		sum += elem;
	}
	if(neg || pos) mins *= 2;
	else mins = 0;
	cout << sum - mins << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll mins = -1;
	ll sum = 0;
	bool neg = false;
	bool pos = false;
	for(int i = 0; i < n; i++) {
		ll elem;
		cin >> elem;
		if(elem < 0) {
			elem *= -1;
			neg = true;
		} else pos = true;
		if(elem < mins || mins == -1) mins = elem;
		sum += elem;
	}
	if(neg && pos) mins = 0;
	else mins *= 2;
	cout << sum - mins << endl;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define ll long long int

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	if(n == 1) {
	    ll tmp;
	    cin >> tmp;
	    cout << tmp << endl;
	}
	ll mins = -1;
	ll sum = 0;
	bool neg = false;
	bool pos = false;
	for(int i = 0; i < n; i++) {
		ll elem;
		cin >> elem;
		if(elem < 0) {
			elem *= -1;
			neg = true;
		} else if(elem > 0) pos = true;
		if(elem < mins || mins == -1) mins = elem;
		sum += elem;
	}
	if(neg && pos) mins = 0;
	else mins *= 2;
	cout << sum - mins << endl;
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=5e5+10;
long long a[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        long long sum=0;
        long long Maxn=-Inf,Minn=Inf;
        for(int i=0; i<n; i++)
        {
            scanf("%lld",&a[i]);
            Maxn=max(Maxn,a[i]);
            Minn=min(Minn,a[i]);
            sum+=abs(a[i]);
        }

        if(n==1)
            printf("%lld\n",a[0]);
        else if(n==2)
            printf("%lld\n",max(a[0]-a[1],a[1]-a[0]));
        else
        {
            if(Minn>0)
                sum=sum-2*Minn;
            else if(Maxn<0)
                sum=sum-2*abs(Maxn);
            printf("%lld\n",sum);
        }

    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f3f
using namespace std;
typedef long long ll;
const long long maxn=5e5+10;
long long a[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int flag=0;
        long long sum=0;
        long long Maxn=-Inf,Minn=Inf;
        for(int i=0; i<n; i++)
        {
            scanf("%lld",&a[i]);
            Maxn=max(Maxn,a[i]);
            Minn=min(Minn,a[i]);
            sum+=abs(a[i]);
            if(a[i]<0)
                flag++;
        }
        if(flag!=0&&flag!=n)
        {
            printf("%lld\n",sum);
        }
        else if(flag==n)
        {
            printf("%lld\n",sum-2*Maxn);
        }
        else if(flag==0)
            printf("%lld\n",sum-2*Minn);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f
using namespace std;
typedef long long ll;
const int maxn=5e5+10;
int a[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int flag=0;
        int sum=0;
        int Maxn=Inf,minn=-Inf;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            Maxn=max(minn,abs(a[i]));
            minn=min(Maxn,abs(a[i]));
            sum+=abs(a[i]);
            if(a[i]<0)
                flag++;
        }
        if(flag!=0&&flag!=n)
        {
           printf("%d\n",sum);
        }
        else if(flag==n)
        {
            printf("%d\n",sum-2*Maxn);
        }
        else if(flag==0)
            printf("%d\n",sum-2*minn);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f
using namespace std;
typedef long long ll;
const int maxn=5e5+10;
long long a[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int flag=0;
        long long sum=0;
        int Maxn=Inf,minn=-Inf;
        for(int i=0; i<n; i++)
        {
            scanf("%lld",&a[i]);
            Maxn=max(minn,abs(a[i]));
            minn=min(Maxn,abs(a[i]));
            sum+=abs(a[i]);
            if(a[i]<0)
                flag++;
        }
        if(flag!=0&&flag!=n)
        {
           printf("%lld\n",sum);
        }
        else if(flag==n)
        {
            printf("%lld\n",sum-2*Maxn);
        }
        else if(flag==0)
            printf("%lld\n",sum-2*minn);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f3f
using namespace std;
typedef long long ll;
const long long maxn=5e5+10;
long long a[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int flag=0;
        long long sum=0;
        long long  Maxn=Inf,minn=-Inf;
        for(int i=0; i<n; i++)
        {
            scanf("%lld",&a[i]);
            Maxn=max(minn,abs(a[i]));
            minn=min(Maxn,abs(a[i]));
            sum+=abs(a[i]);
            if(a[i]<0)
                flag++;
        }
        if(flag!=0&&flag!=n)
        {
           printf("%lld\n",sum);
        }
        else if(flag==n)
        {
            printf("%lld\n",sum-2*Maxn);
        }
        else if(flag==0)
            printf("%lld\n",sum-2*minn);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=5e5+10;
long long a[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int flag=0;
        long long sum=0;
        long long  Maxn=Inf,minn=-Inf;
        for(int i=0; i<n; i++)
        {
            scanf("%lld",&a[i]);
            Maxn=max(minn,a[i]);
            minn=min(Maxn,a[i]);
            sum+=abs(a[i]);
            if(a[i]<0)
                flag++;
        }
        if(n==1)
            printf("%lld\n",a[0]);
        else if(n==2)
            printf("%lld\n",max(a[0]-a[1],a[1]-a[0]));
        else
        {
            if(minn>0)
                sum=sum-2*minn;
            else if(Maxn<0)
                sum=sum-2*abs(Maxn);
            printf("%lld\n",sum);
        }

    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f3f3f
using namespace std;
typedef long long ll;
const int maxn=5e5+10;
long long a[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int flag=0;
        long long sum=0;
        long long  Maxn=Inf,minn=-Inf;
        for(int i=0; i<n; i++)
        {
            scanf("%lld",&a[i]);
            Maxn=max(minn,a[i]);
            minn=min(Maxn,a[i]);
            sum+=abs(a[i]);
            if(a[i]<0)
                flag++;
        }
        if(n==1)
            printf("%lld\n",a[0]);
        else if(n==2)
        {
            printf("%lld\n",max(a[0]-a[1],a[1]-a[0]));
        }
        else
        {
            if(flag!=0&&flag!=n)
            {
                printf("%lld\n",sum);
            }
            else if(flag==n)
            {
                printf("%lld\n",sum-2*abs(Maxn));
            }
            else if(flag==0)
                printf("%lld\n",sum-2*minn);
        }

    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#define Inf 0x3f3f3f
using namespace std;
typedef long long ll;
const int maxn=5e5+10;
int a[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n))
    {
        int flag=0;
        long long sum=0;
        int Maxn=Inf,minn=-Inf;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&a[i]);
            Maxn=max(minn,abs(a[i]));
            minn=min(Maxn,abs(a[i]));
            sum+=abs(a[i]);
            if(a[i]<0)
                flag++;
        }
        if(flag!=0&&flag!=n)
        {
           printf("%lld\n",sum);
        }
        else if(flag==n)
        {
            printf("%lld\n",sum-2*Maxn);
        }
        else if(flag==0)
            printf("%lld\n",sum-2*minn);
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define ull unsigned long long int
#define f(a,b) for(ll i=a;i<b;i++)
#define f1(a,b) for(ll i=a;i<=b;i++)
#define fd(a,b) for(ll i=a;i>=b;i--)
#define fj(j,a,b) for(ll j=a;j<b;j++)
#define fk(k,a,b) for(ll k=a;k<b;k++)
#define fat(m) for(auto it:m)
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vp vector<pair<int,int>>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define alld(v) v.begin(),v.end(),greater<int>()
#define sz(v) v.size()
#define endl "\n"
#define ff first
#define ss second
const ll N=1e5+1;

void solve()
{
    ll n,m,k,p=0,q=0,s=0,c=0,i,j;
    cin>>n;
    ll a[n]={0};
    if(n==1)
    {
        cin>>a[0];
        cout<<a[0];
        return;
    }
    ll c1=1e18,c2=c1;
    f(0,n)
    {
        cin>>a[i];
        if(a[i]<=0)
            p++,
            c1=min(a[i],c1);
        if(a[i]>=0)
            q++,
            c2=min(a[i],c2);

        s+=llabs(a[i]);
    }
  //  cout<<c<<" "<<s<<endl;
    //cout<<p<<" "<<q<<endl;
    if(p&&q)
    {
        cout<<s;
        return;
    }
    if(p==0)
        cout<<s-2*c2;
    else cout<<s-2*c1;

    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
  //  cin>>t;
    while(t--)
    {
        solve();
    }
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define ull unsigned long long int
#define f(a,b) for(ll i=a;i<b;i++)
#define f1(a,b) for(ll i=a;i<=b;i++)
#define fd(a,b) for(ll i=a;i>=b;i--)
#define fj(j,a,b) for(ll j=a;j<b;j++)
#define fk(k,a,b) for(ll k=a;k<b;k++)
#define fat(m) for(auto it:m)
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vp vector<pair<int,int>>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define alld(v) v.begin(),v.end(),greater<int>()
#define sz(v) v.size()
#define endl "\n"
#define ff first
#define ss second
const ll N=1e5+1;

void solve()
{
    ll n,m,k,p=0,q=0,s=0,c=0,i,j;
    cin>>n;
    ll a[n]={0};
    if(n==1)
    {
        cin>>a[0];
        cout<<a[0];
        return;
    }
    ll c1=1e18,c2=c1;
    f(0,n)
    {
        cin>>a[i];
        if(a[i]<=0)
            p++,
            c1=min(llabs(a[i]),c1);
        if(a[i]>=0)
            q++,
            c2=min(llabs(a[i]),c2);

        s+=llabs(a[i]);
    }
 //   cout<<c<<" "<<s<<endl;
   // cout<<p<<" "<<q<<endl;
    if(p&&q)
    {
        cout<<s;
        return;
    }
    if(p==0)
        cout<<s-2*llabs(c2);
    else cout<<s-2*llabs(c1);

    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
  //  cin>>t;
    while(t--)
    {
        solve();
    }
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define ull unsigned long long int
#define f(a,b) for(ll i=a;i<b;i++)
#define f1(a,b) for(ll i=a;i<=b;i++)
#define fd(a,b) for(ll i=a;i>=b;i--)
#define fj(j,a,b) for(ll j=a;j<b;j++)
#define fk(k,a,b) for(ll k=a;k<b;k++)
#define fat(m) for(auto it:m)
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vp vector<pair<int,int>>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define alld(v) v.begin(),v.end(),greater<int>()
#define sz(v) v.size()
#define endl "\n"
#define ff first
#define ss second
const ll N=1e5+1;

void solve()
{
    ll n,m,k,p=0,q=0,s=0,c=0,i,j;
    cin>>n;
    ll a[n]={0};
    ll c1=1e18,c2=c1;
    f(0,n)
    {
        cin>>a[i];
        if(a[i]<0)
            p++,
            c1=min(a[i],c1);
        else
            q++,
            c2=min(a[i],c2);
        s+=llabs(a[i]-0LL);
    }
    if(n==1)
    {
        cout<<a[0];
        return;
    }
    if(p&&q)
    {
        cout<<s;
        return;
    }
    if(p==0)
        cout<<s-2*c2;
    else cout<<s-2*c1;

    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
  //  cin>>t;
    while(t--)
    {
        solve();
    }
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
    #endif
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define ll long long int
#define ull unsigned long long int
#define f(a,b) for(ll i=a;i<b;i++)
#define f1(a,b) for(ll i=a;i<=b;i++)
#define fd(a,b) for(ll i=a;i>=b;i--)
#define fj(j,a,b) for(ll j=a;j<b;j++)
#define fk(k,a,b) for(ll k=a;k<b;k++)
#define fat(m) for(auto it:m)
ll power(ll x,ll y,ll p){ll res=1;x=x%p;while(y>0){if(y&1)res=((res%p)*(x%p))%p;y=y>>1;x=(x*x)%p;}return res;}
ll pow1(ll x,ll y){ll res=1;while(y>0){if(y&1)res=(res*x);y=y>>1;x=x*x;}return res;}
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vector<int>>
#define vvll vector<vector<ll>>
#define vp vector<pair<int,int>>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(v) v.begin(),v.end()
#define alld(v) v.begin(),v.end(),greater<int>()
#define sz(v) v.size()
#define endl "\n"
#define ff first
#define ss second
const ll N=1e5+1;

void solve()
{
    ll n,m,k,p=0,q=0,s=0,c=0,i,j;
    cin>>n;
    ll a[n]={0};
    if(n==1)
    {
        cin>>a[0];
        cout<<a[0];
        return;
    }
    ll c1=1e18,c2=c1;
    f(0,n)
    {
        cin>>a[i];
        if(a[i]<=0)
            p++,
            c1=min(llabs(a[i]),c1);
        if(a[i]>=0)
            q++,
            c2=min(llabs(a[i]),c2);

        s+=llabs(a[i]);
    }
    cout<<c<<" "<<s<<endl;
    cout<<p<<" "<<q<<endl;
    if(p&&q)
    {
        cout<<s;
        return;
    }
    if(p==0)
        cout<<s-2*llabs(c2);
    else cout<<s-2*llabs(c1);

    return;
}

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "rt", stdin);
        freopen("output.txt", "wt", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t=1;
  //  cin>>t;
    while(t--)
    {
        solve();
    }
    #ifndef ONLINE_JUDGE
        cout<<"\nTime Elapsed: "<<1000*(long double)clock()/(long double)CLOCKS_PER_SEC<<"ms\n";
    #endif
    return 0;
}