#include<stdio.h>
int main ()
{
    int t , i , n , m ,  j ;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d %d",&n,&m);
        int arr[n][m];
        int flag, nn=0 ,mm=0;
        for(i=0 ; i < n ;i++)
            for(j=0 ; j<m ; j++)
                 scanf("%d",&arr[i][j]);
        for(i=0 ; i<n ;i++)
        {
            flag=1;
            for(j=0; j<m ;i++)
            {
                if(arr[i][j]) flag=0;
            }
            if(flag)nn++;
        }
        for(i=0 ; i<m ;i++)
        {
            flag=1;
            for(j=0; j<n ;i++)
            {
                if(arr[i][j]) flag=0;
            }
            if(flag)mm++;
        }
        flag=nn>mm?nn:mm;
        if(flag%2) puts("Ashish");
        else if(flag%2==0) puts("Vivek");
    }
    return 0;
}


#include<stdio.h>
main(void)
{
	int t,n,m,i,j,arr[50][50],nn,flag,nn;
	scanf("%d",&t);
	while(t--){
		scanf("%d %d",&n,&m);
		for(i=0;i<n;i++){
			for(j=0;j<m;j++)scanf("%d",&arr[i][j]);
		}
		nn=0;
		mm=0;
		for(i=0;i<n;i++){
			flag=1;
			for(j=0;j<m;j++){
				if(arr[i][j])flag=0;
			}
			if(flag)nn++;
		}
		for(j=0;j<m;j++){
			flag=1;
			for(i=0;i<n;i++){
				if(arr[i][j])flag=0;
			}
			if(flag)mm++;
		}
		if(nn>mm)flag=mm;
		else flag=nn;
		if(flag%2)printf("Ashish\n");
		else printf("Vivek\n");
	}
}


#include <stdio.h>

int main(void) {
	int t;
	scanf("%d",&t);
	while(t--){
	    int n,m,i,j,c=0,found=0,d=0,flag=0,ans;
	    scanf("%d %d",&n,&m);
	    int a[n][m];
	    for(i=0;i<n;i++){
	        for(j=0;j<m;j++){
	            scanf("%d",&a[i][j]);
	        }
	    }
	    for(j=0;j<m;j++){
	        found=0;
	        for(i=0;i<n;i++){
	            if(a[i][j]==1)
	            {found=1;
	                break;}
	        }
	        if(found==0)
	        c++;
	    }
	    for(i=0;i<n;i++){
	        flag=0;
	        for(j=0;j<m;j++){
	            if(a[i][j]==1)
	            {flag=1;
	            break;}
	        }
	        if(flag==0)
	        d++;
	    }
	    if(d<c)
	    ans=d;
	    else
	    ans=c;
	    if(ans%2==0)
	    printf("Vivek\n");
	    else
	    printf("Ashish\n");

	}
	return 0;
}


#include<stdio.h>

int main(void){

    long long int i,t,n,k,c=0,j,m,a[100][100],rows=0,column=0,min=0;
    scanf("%lld", &t);

    for(i=0;i<t;i++){

        scanf("%lld %lld", &n, &m);

        c=0;
        rows=0;
        column=0;
        for(j=0;j<n;j++){
            for(k=0;k<m;k++){
                scanf("%lld", &a[j][k]);

            }
        }

        for(j=0;j<n;j++){
                c=0;
            for(k=0;k<m;k++){
                if(a[j][k]==1){
                    break;
                }
                else{
                    c++;
                }

            }
            if(c==m){
                rows++;
            }

        }

        for(j=0;j<m;j++){
                c=0;
            for(k=0;k<n;k++){
                if(a[j][k]==1){
                    break;
                }
                else{
                    c++;
                }

            }
            if(c==n){
                column++;
            }

        }

        if(rows<=column)
            min=rows;
        else
            min=column;

        if(min%2==0)
            printf("Vivek\n");

        else
            printf("Ashish\n");}}


#include<stdio.h>

int main(void){

    long long int i,t,n,k,c=0,j,m,a[100][100];
    scanf("%lld", &t);

    for(i=0;i<t;i++){

        scanf("%lld %lld", &n, &m);

        c=0;

        for(j=0;j<n;j++){
            for(k=0;k<m;k++){
                scanf("%lld", &a[j][k]);
                if(a[j][k]==1){
                    c++;
                }
            }
        }

        if(((n*m)-c)%2==0)
            printf("Vivek\n");

        else
            printf("Ashish\n");}}


#include<stdio.h>

int main(void){

    long long int i,t,n,k,c=0,j,m,a[100][100],rows=0,column=0,min=0;
    scanf("%lld", &t);

    for(i=0;i<t;i++){

        scanf("%lld %lld", &n, &m);

        c=0;
        rows=0;
        column=0;
        for(j=0;j<n;j++){
            for(k=0;k<m;k++){
                scanf("%lld", &a[j][k]);

            }
        }

        for(j=0;j<n;j++){
                c=0;
            for(k=0;k<m;k++){
                if(a[j][k]==1){
                    break;
                }
                else{
                    c++;
                }

            }
            if(c==m){
                rows++;
            }

        }

        for(j=0;j<m;j++){
                c=0;
            for(k=0;k<n;k++){
                if(a[k][j]==1){
                    break;
                }
                else{
                    c++;
                }

            }
            if(c==n){
                column++;
            }

        }

        if(rows<=column)
            min=rows;
        else
            min=column;

        if(min%2==0)
            printf("Vivek\n");

        else
            printf("Ashish\n");}}


#include<stdio.h>

int main() {
    int t,i,j,k,m,n;
    int countn=0,countm=0;
	scanf("%d",&t);
	for(k=0;k<t;k++)
	{
	    int box=0;
	    scanf("%d %d",&n,&m);
	    int arrm[m],arrn[n];
	    for(i=0;i<n;i++)
	   {
	       arrn[i]=0;

	   }
	   for(j=0;j<m;j++)
	   {
	       arrm[j]=0;

	   }

	    for(i=0;i<n;i++)
	    {
	       for(j=0;j<m;j++)
	       {
	          scanf("%d",&box);
	          if (box==1)
	          {
	              arrm[j]=-1;
	              arrn[i]=-1;
	          }
	       }

	    }
	   int countn=0,countm=0;
	   for(i=0;i<n;i++)
	   {
	       if(arrn[i]==0){countn++;}

	   }
	   for(j=0;j<m;j++)
	   {
	       if(arrm[j]==0){countm++;}

	   }

	   int sum=0;
	   sum=min(countn,countm);
	   if(sum%2==0){
	       printf("Vivek\n");
	   }
	   else{
			printf("Ashish\n");
	   }
	}
return 0;
}

int min(a,b)
{
	return a < b ? a : b;
}


#include <stdio.h>

int main (void)
{
	int t;
	scanf("%d",&t);
	char R[t];
	for (int z=0;z<t;z++)
	{
		int m,n;
		scanf("%d%d",&n,&m);
		int A[n][m];
		int Row[n];
		int Clmn[m];
		for (int i=0;i<n;i++)
			Row[i]=0;
		for (int i=0;i<m;i++)
			Clmn[i]=0;
		for (int i=0;i<n;i++)
		{
			for (int j=0;j<m;j++)
			{
				scanf("%d",&A[i][j]);
				if (A[i][j]==1)
				{
					Row[i]=1;
					Clmn[j]=1;
				}
			}
		}
		int r=0,c=0;
		for (int i=0;i<n;i++)
			if (Row[i]==0)
				r++;
		for (int i=0;i<m;i++)
			if (Clmn[i]==0)
				c++;
		int min=(r<c)?r:c;
		if (min%2==0)
			R[z]='V';
		else
			R[z]='A';
	}
	for (int i=0;i<t;i++)
		if (R[i]=='A')
			printf("Ashish\n");
		else
			printf("Vivek\n");
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    int t,m,n,i,j,k,l,p;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&m,&n);
        k=0;
        for(i=0;i<m;i++)
        {
            l=0;
            for(j=0;j<n;j++)
            {
                scanf("%d",&p);
                if(p==1)
                l=1;
            }
            if(l==0)
            k++;
        }
        if(k%2==0)
        printf("Vivek\n");
        else
        printf("Ashish\n");
    }
    return 0;
}


#include<stdio.h>
int main(){int t,i,j,n,m,k,colr,colc,col[55],row[55],a[55][55];
    scanf("%d",&t);
    for(i=0;i<t;i++)
    {
        scanf("%d%d",&n,&m);
        for(j=0;j<n;j++)
        {
            for(k=0;k<m;k++)
            {
                scanf("%d",&a[j][k]);
            }
        }
        for(j=0;j<n;j++)
        {
            col[j]=0;
        }
        for(j=0;j<n;j++)
        {
            for(k=0;k<m;k++)
            {
                col[j]=col[j]+a[j][k];
            }
        }
        for(k=0;k<m;k++)
        {
            row[k]=0;
        }
        for(j=0;j<n;j++)
        {
            for(k=0;k<m;k++)
            {
                row[k]=row[k]+a[j][k];
            }
        }
        colc=0;
        for(j=0;j<n;j++)
        {
            if(col[j]==0)
            colc++;
        }
        colr=0;
        for(k=0;k<m;k++)
        {
            if(row[k]==0)
            colr++;
        }
        if(colr>colc)
        {
            if(colc%2==0)
            printf("Vivek\n");
            else
            printf("Ashish\n");
        }
        else
        {
            if(colr%2==0)
            printf("Vivek\n");
            else
            {
                printf("Ashish\n");
            }
        }
    }
    return 0;
}


#include<stdio.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d %d",&n,&m);
        int arr[n][m],row[n],column[m],i,j;
        for(i=0;i<n;i++)row[i]=0;
        for(i=0;i<m;i++)column[i]=0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%d",&arr[i][j]);
                printf("%d ",arr[i][j])
                if(arr[i][j]==1)
                {
                    row[i]=1;
                    column[j]=1;
                }
            }
        }
        i=0;
        j=0;
        // for(i=0;i<n;i++)printf("%d ",row[i]);
        // printf("\n");
        // for(i=0;i<m;i++)printf("%d ",column[j]);
        printf("\n");
        int winner = 1;
        while(i<n && j<m)
        {
            if(row[i]==1)i++;
            if(column[j]==1)j++;
            if(row[i]==0&&column[j]==0)
            {
                winner=1-winner;
                i++;
                j++;
            }
        }
        if(winner==1)printf("Vivek\n");
        else printf("Ashish\n");

    }
}


#include<stdio.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d %d",&n,&m);
        int arr[n][m],row[n],column[m],i,j;
        for(i=0;i<n;i++)row[i]=0;
        for(i=0;i<m;i++)column[i]=0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%d",&arr[i][j]);
                // printf("%d ",arr[i][j]);
                if(arr[i][j]==1)
                {
                    row[i]=1;
                    column[j]=1;
                }
            }
        }
        i=0;
        j=0;
        // for(i=0;i<n;i++)printf("%d ",row[i]);
        // printf("\n");
        // for(i=0;i<m;i++)printf("%d ",column[j]);
        printf("\n");
        int winner = 1;
        while(i<n && j<m)
        {
            if(row[i]==1)i++;
            if(column[j]==1)j++;
            if(row[i]==0&&column[j]==0)
            {
                winner=1-winner;
                i++;
                j++;
            }
        }
        if(winner==1)printf("Vivek\n");
        else printf("Ashish\n");

    }
}


#include<stdio.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d %d",&n,&m);
        int arr[n][m],row[n],column[m],i,j;
        for(i=0;i<n;i++)row[i]=0;
        for(i=0;i<m;i++)column[i]=0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%d",&arr[i][j]);
                // printf("%d ",arr[i][j]);
                if(arr[i][j]==1)
                {
                    row[i]=1;
                    column[j]=1;
                }
            }
        }
        i=0;
        j=0;
        // for(i=0;i<n;i++)printf("%d ",row[i]);
        // printf("\n");
        // for(i=0;i<m;i++)printf("%d ",column[j]);
        // printf("\n");
        int winner = 1;
        while(i<n && j<m)
        {
            if(row[i]==1)i++;
            if(column[j]==1)j++;
            if(row[i]==0&&column[j]==0)
            {
                winner=1-winner;
                i++;
                j++;
            }
        }
        if(winner==1)printf("Vivek\n");
        else printf("Ashish\n");

    }
}


#include<stdio.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d %d",&n,&m);
        int arr[n][m],row[n],column[m],i,j;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                row[i]=0;
                column[j]=0;
                scanf("%d",&arr[i][j]);
                if(arr[i][j]==1)
                {
                    row[i]=1;
                    column[j]=1;
                }
            }
        }
        i=0;
        j=0;
        int winner = 1;
        while(i<n && j<m)
        {
            if(row[i]==1)i++;
            if(column[j]==1)j++;
            if(row[i]==0&&column[j]==0)
            {
                winner=1-winner;
                i++;
                j++;
            }
        }
        if(winner==1)printf("Vivek\n");
        else printf("Ashish\n");
        for(i=0;i<n;i++)printf("%d ",row[i]);
        printf("\n");
        for(i=0;i<m;i++)printf("%d ",column[j]);

    }
}


#include<stdio.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d %d",&n,&m);
        int arr[n][m],row[n],column[m],i,j;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                row[i]=0;
                column[j]=0;
                scanf("%d",&arr[i][j]);
                if(arr[i][j]==1)
                {
                    row[i]=1;
                    column[j]=1;
                }
            }
        }
        i=0;
        j=0;
        for(i=0;i<n;i++)printf("%d ",row[i]);
        printf("\n");
        for(i=0;i<m;i++)printf("%d ",column[j]);
        printf("\n");
        int winner = 1;
        while(i<n && j<m)
        {
            if(row[i]==1)i++;
            if(column[j]==1)j++;
            if(row[i]==0&&column[j]==0)
            {
                winner=1-winner;
                i++;
                j++;
            }
        }
        if(winner==1)printf("Vivek\n");
        else printf("Ashish\n");

    }
}


#include<stdio.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d %d",&n,&m);
        int arr[n][m],row[n],column[m],i,j;
        for(i=0;i<n;i++)row[i]=0;
        for(i=0;i<m;i++)column[i]=0;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%d",&arr[i][j]);
                if(arr[i][j]==1)
                {
                    row[i]=1;
                    column[j]=1;
                }
            }
        }
        i=0;
        j=0;
        for(i=0;i<n;i++)printf("%d ",row[i]);
        printf("\n");
        for(i=0;i<m;i++)printf("%d ",column[j]);
        printf("\n");
        int winner = 1;
        while(i<n && j<m)
        {
            if(row[i]==1)i++;
            if(column[j]==1)j++;
            if(row[i]==0&&column[j]==0)
            {
                winner=1-winner;
                i++;
                j++;
            }
        }
        if(winner==1)printf("Vivek\n");
        else printf("Ashish\n");

    }
}


#include<stdio.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d %d",&n,&m);
        int arr[n][m],row[n],column[m],i,j;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%d",&arr[i][j]);
                if(arr[i][j]==1)
                {
                    row[i]=1;
                    column[j]=1;
                }
            }
        }
        i=0;
        j=0;
        int winner = 1;
        while(i<n && j<m)
        {
            if(row[i]==1)i++;
            if(column[j]==1)j++;
            if(row[i]==0&&column[j]==0)
            {
                winner=1-winner;
                i++;
                j++;
            }
        }
        if(winner==1)printf("Vivek\n");
        else printf("Ashish\n");

    }
}


#include<stdio.h>

int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        int n,m;
        scanf("%d %d",&n,&m);
        int arr[n][m],row[n],column[m],i,j;
        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                scanf("%d",&arr[i][j]);
                if(arr[i][j]==1)
                {
                    row[i]=1;
                    column[j]=1;
                }
            }
        }
        i=0;
        j=0;
        int winner = 1;
        // while(i<n && j<m)
        // {
        //     if(row[i]==1)i++;
        //     if(column[j]==1)j++;
        //     if(row[i]==0&&column[j]==0)
        //     {
        //         winner=1-winner;
        //         i++;
        //         j++;
        //     }
        // }
        if(winner==1)printf("Vivek\n");
        else printf("Ashish\n");

    }
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
	int n,*a,i,j=-1;
	scanf("%d",&n);
	a=(int *)malloc(n*sizeof(int));
	int ans=0;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		ans=ans+a[i];
	}
	int min1,min2;
	min1=0;min2=0;
	int temp=0;
	for(i=0;i<n;i++)
	{
		temp=temp+a[i];
		if(temp<min1)
		{
			min1=temp;
			j=i;
		}
	}
	if(j>=0)
	{
		for(i=0;i<=j;i++)
		a[i]=-1*a[i];
	}
	temp=0;
	for(i=n-1;i>=0;i--)
	{
		temp=temp+a[i];
		if(temp<min2)
			min2=temp;
	}
	printf("%d\n",(ans-2*(min1+min2)));
	temp=0;
	return 0;
}


#include<stdio.h>
int main()
{
	int sum=0,max,maxsum;
	int n,a[10000];
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		sum+=a[i];
	max=a[0],maxsum=a[0];
	for(i=1;i<n;i++)
	{
		if(max<0)
		{
			max=0;
		}
		max+=a[i];
		if(max>maxsum)
			maxsum=max;
	}
	printf("%d\n",(2*maxsum-sum));
	return 0;
}


#include<stdio.h>
int main()
{
	int sum=0,max,maxsum;
	int n,a[10000];
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	for(i=0;i<n;i++)
		sum+=a[i];
	max=0,maxsum=0;
	for(i=0;i<n;i++)
	{

		max+=a[i];
		if(max<0)
			max=0;
		if(max>maxsum)
			maxsum=max;
	}
	printf("%d\n",(2*maxsum-sum));
	return 0;
}


#include<stdio.h>
int main()
{
	int sum=0,max,maxsum;
	int n,a[10000];
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	max=0;maxsum=0;
	for(i=0;i<n;i++)
	{
		sum+=a[i];
		max+=a[i];
		if(max<0)
			max=0;
		if(max>maxsum)
			maxsum=max;
	}
	printf("%d\n",(2*maxsum-sum));
	return 0;
}


#include<stdio.h>
int main()
{
	int sum=0,max,maxsum;
	int n,a[100000];
	scanf("%d",&n);
	int i;
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	max=0;maxsum=0;
	for(i=0;i<n;i++)
	{
		sum+=a[i];
		max+=a[i];
		if(max<0)
			max=0;
		if(max>maxsum)
			maxsum=max;
	}
	printf("%d\n",(2*maxsum-sum));
	return 0;
}


#include<stdio.h>
int main()
{	int n,i,j,mcs,sum=0,totsum=0,subi,subj;
	scanf("%d",&n);
	int arr[n];
	for(i=0;i<n;i++)
	{	scanf("%d",&arr[i]);
		totsum+=arr[i];
	}
	mcs=arr[0];
	for(j=0;j<n;j++)
	{       sum=0;
		for(i=j;i<n;i++)
		{       sum+=arr[i];
			if(sum>=mcs)
				mcs=sum;
		}
	}
	if(mcs<0)
		printf("%d\n",-1*totsum);
	else
		printf("%d\n",2*mcs-totsum);
	return 0;
}


#include<stdio.h>
int main()
{	int n,i,j,mcs,sum=0,totsum=0,subi,subj;
	scanf("%d",&n);
	int arr[100001];
	for(i=0;i<n;i++)
	{	scanf("%d",&arr[i]);
		totsum+=arr[i];
	}
	mcs=arr[0];
	for(j=0;j<n;j++)
	{      // sum=0;
		sum+=arr[j];
		if(sum<0)
			sum=0;
		if(sum>=mcs)
			mcs=sum;
	}
	if(mcs<0)
		printf("%d\n",-1*totsum);
	else
		printf("%d\n",2*mcs-totsum);
	return 0;
}


#include<stdio.h>
int main()
{	int n,i,j,mcs,sum=0,totsum=0,subi,subj;
	scanf("%d",&n);
	int arr[n];
	for(i=0;i<n;i++)
	{	scanf("%d",&arr[i]);
		totsum+=arr[i];
	}
	mcs=arr[0];
	for(j=0;j<n-1;j++)
	{       sum=0;
		for(i=j;i<n;i++)
		{       sum+=arr[i];
			if(sum>=mcs)
				mcs=sum;
		}
	}
	if(mcs<0)
		printf("%d\n",-1*totsum);
	else
		printf("%d\n",2*mcs-totsum);
	return 0;
}


#include <stdio.h>

int main(){
  int numbers[100001], prefix[100001], sufix[100001];
  int n, i, min, sum, tmp;

  scanf("%d", &n);

  prefix[0] = sufix[n] = 0;

  for(i=1; i <= n; i++)
    scanf("%d", &numbers[i]);

  for(i=1; i <= n; i++)
    prefix[i] = prefix[i-1] + numbers[i];

  for(i=n-1; i >= 0; i--)
    sufix[i] = sufix[i+1] + numbers[i+1];

  min = sum = 0;
  for(i=0; i <= n; i++){
    if(prefix [i] < min)
      min = prefix[i];

    tmp = prefix[i] - sufix[i] - 2*min;
    if(tmp > sum)
      sum = tmp;
  }

  printf("%d\n", sum);

  return 0;
}


#include <stdio.h>

#define oo 20000000000000000

long long s[200005]={0};

int main()
{
 long long n;
 long long i;
 long long min=0;
 long long ans=0;

 scanf("%I64d",&n);

 for(i=1;i<=n;i++)
   {
    scanf("%I64d",&s[i]);
    s[i]+=s[i-1];
    if(s[i]<min)
     min=s[i];
    if(2*(s[i]-min)>ans)
     ans=2*(s[i]-min);
   }

 ans-=s[n];

 printf("%I64d\n",ans);

 return 0;
}


#include<stdio.h>
#include<string.h>

int a[100000];
int main()
{
    int n,i,j,max,sum,total,x,ans;

    scanf("%d",&n);
    n--;
    scanf("%d",&x);
    total=sum=x;
    max=0;
    if(x>0)max=x;
    for(i=0;i<n;i++)
    {
    if(sum<0)sum=0;
    scanf("%d",&x);
    total+=x;
    sum+=x;
    if(sum>max)
        max=sum;
    }
    ans=max-(total-max);
    printf("%d\n",ans);
    return 0;
}


#include<stdio.h>

int main()
{
	int i, size, sum, ThisSum, MaxSum, arr[100001];
	scanf("%d", &size);
	sum = MaxSum = ThisSum = 0;
	for(i=0;i<size;i++)
	{
		scanf("%d", &arr[i]);
		sum+=arr[i];
		ThisSum+=arr[i];
		if(ThisSum>MaxSum)
			MaxSum = ThisSum;
		else if(ThisSum<0)
			ThisSum = 0;
	}
	printf("%d\n", 2*MaxSum - sum);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
  int i,j,k,l,m,n;
  int in[110000];
  int sum1[110000], sum2[110000];
  int res, mx, tmp;

  scanf("%d",&n);
  rep(i,n) scanf("%d",in+i+1);
  in[0]=in[n+1]=0; n+=2;

  sum1[0]=sum2[n-1]=0;
  REP(i,1,n) sum1[i]=sum1[i-1]+in[i];
  for(i=n-2;i>=0;i--) sum2[i]=sum2[i+1]+in[i];

  res = sum1[n-1];
  REP(i,1,n-1){
    if(mx > sum1[i]) mx = sum1[i];
    tmp = sum1[i] - mx - mx - sum2[i+1];
    if(tmp > res) res = tmp;
  }
  printf("%d\n",res);

  return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
  int i,j,k,l,m,n;
  int in[110000];
  int sum1[110000], sum2[110000];
  int res, mx, tmp;

  scanf("%d",&n);
  rep(i,n) scanf("%d",in+i+1);
  in[0]=in[n+1]=0; n+=2;

  sum1[0]=sum2[n-1]=0;
  REP(i,1,n) sum1[i]=sum1[i-1]+in[i];
  for(i=n-2;i>=0;i--) sum2[i]=sum2[i+1]+in[i];

  res = sum1[n-1]; mx=0;
  REP(i,1,n-1){
    if(mx > sum1[i]) mx = sum1[i];
    tmp = sum1[i] - mx - mx - sum2[i+1];
    if(tmp > res) res = tmp;
  }
  printf("%d\n",res);

  return 0;
}


#include<stdio.h>

int main()
{
	int s,n,i,mx,sum;
	scanf("%d",&n);
	int a[n];
	s=0;
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		s+=a[i];
	}

	mx = 0;
	for(i=0;i<n;++i)
	{
		sum += a[i];
		if(sum < 0)
			sum = 0;
		if(sum > mx)
			mx=sum;
	}
	mx=2*mx-s;
	printf("%d\n",mx);
	return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define REP(i,a,b) for(i=a;i<b;i++)
#define REPi(i,a,b) for(i=a-1;i>=b;i--)
#define rep(i,b) REP(i,0,b)
#define repi(i,b) REPi(i,b,0)
#define si(n) scanf("%d",&n)
#define sort(arrr,n) qsort(arrr,n,sizeof(int),compare)
#define min(a,b) (a<b?a:b)
#define pi(n) printf("%d\n",n)
int a[100000];
int main()
{
    int n,i,j,max,sum,total,x,ans;

    si(n);
    n--;
    si(x);
    total=sum=x;
    max=0;
    if(x>0)max=x;
    rep(i,n)
    {
	if(sum<0)sum=0;
	si(x);
	total+=x;
	sum+=x;
	if(sum>max)max=sum;
    }
    ans=max-(total-max);
    printf("%d",ans);
    return 0;
}


#include<stdio.h>
#define maxi(a,b) ((a>b)?a:b);

int main()
{
    int i,sum=0,n,max=0,a[10001],s=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
	scanf("%d",&a[i]);
	s+=a[i];
	sum=maxi(a[i],sum+a[i]);
	if(sum>max)
	    max=sum;
    }
    printf("%d ",2*max-s);//max=sum of middle elements
   return 0;
}


#include<stdio.h>
#define maxi(a,b) ((a>b)?a:b);

int main()
{
    int i,sum=0,n,max=0,a[100001],s=0;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
	scanf("%d",&a[i]);
	s+=a[i];
	sum=maxi(a[i],sum+a[i]);
	if(sum>max)
	    max=sum;
    }
    printf("%d ",2*max-s);//max=sum of middle elements
   return 0;
}


import java.util.*;

public class main
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();

		int[] array = new int[n];
		//int[] prefix = new int[n];
		//int[] suffix = new int[n];
		int sump=Integer.MAX_VALUE;
		int temp=0;
		int sp=-1;
		int sums = Integer.MAX_VALUE;
		int ss=-1;
		//int sum=0;
		for(int y=0; y<n; y++)
		{
			array[y]=s.nextInt();
			temp+=array[y];
			sump=Math.min(sump, temp);
				if(sump==temp)
					sp=y;
			//sum+=array[y];
			//sum+=array[y];
		}
	//	System.out.println(sump);
		if(sump<0)
			sump=-sump;
		temp=0;
		for(int y=n-1;y>=sp+1;y--)
		{
			temp+=array[y];
			sums = Math.min(temp, sums);
			if(sums==temp)
				ss=y;
		}
		sums = Math.min(temp, sums);

		//System.out.println(temp);
		int temp1;
		if(sums<0)
			sums=-sums;
		sump+=sums;
		sums=0;
		for(int y=sp+1;y<ss;y++)
		{
			sums+=array[y];
		}
		sump+=sums;
		temp1=sump;
		sums=Integer.MAX_VALUE;
		ss=-1;
		temp=0;
		sp=0;
		sump=Integer.MAX_VALUE;
		for(int y=n-1; y>=0; y--)
		{
			//array[y]=s.nextInt();
			temp+=array[y];

				sums=Math.min(sums, temp);
				if(sums==temp)
					ss=y;

			//sum+=array[y];
		}
		if(sums<0)
			sums=-sums;
		temp=0;
		for(int y=0;y<ss;y++)
		{
			temp+=array[y];
			sump = Math.min(temp, sump);
			if(sump==temp)
				sp=y;
		}
		sump = Math.min(temp, sump);
		if(sump<0)
			sump=-sump;
		sums+=sump;

		sump=0;
		for(int y=sp+1;y<ss;y++)
		{
			sump+=array[y];
		}
		sums+=sump;
		System.out.println(Math.max(sums,temp1));
	}
}


import java.util.*;

public class Solution
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();

		int[] array = new int[n];
		int[] csum=new int[n];

		for(int i=0;i<n;i++)
		{
			array[i]=s.nextInt();
			if(i==0)
				csum[i]=array[i];
			else
				csum[i]=csum[i-1]+array[i];
		}

		int s1=0,s2=0;

		if(n%2==0)
		{
			s2=n/2;
			s1=n/2;
		}
		else
		{
			s1=n/2;
			s2=n/2;
			s2++;
		}

		int[] prefix = new int[s1];
		int[] suffix = new int[s2];
		int max=0;
		int mi=-1;

		for(int y=0;y<s1;y++)
		{
			if(y==0)
			{
				prefix[0]=array[0];
				if(prefix[0]<max)
				{
					max=prefix[0];
					mi=0;
				}
			}
			else
			{
				prefix[y]=prefix[y-1]+array[y];
				if(prefix[y]<max)
				{
					max=prefix[y];
					mi=y;
				}
			}
		}
		int max2=0;
		int mx2=-1;
		for(int y=n-1;y>=n-s2;y--)
		{
			if(y==n-1)
			{
				suffix[0]=array[n-1];
				if(suffix[0]<max2)
				{
					max2=suffix[0];
					mx2=y;
				}
			}
			else
			{
				suffix[n-1-y]=suffix[n-1-y-1]+array[y];
				if(suffix[n-1-y]<max2)
				{
					max2=suffix[n-1-y];
					mx2=y;
				}
			}
		}

		if(mi==-1 && mx2==-1)
		{
			System.out.println(csum[n-1]);
		}
		else if(mi==-1)
		{
			int print = csum[mx2-1]+(csum[n-1]-csum[mx2-1])*-1;
			System.out.println(print);
		}
		else if(mx2==-1)
		{
			int print = csum[mi]*-1+(csum[n-1]-csum[mi]);
			System.out.println(print);
		}
		else
		{
			int print = csum[mi]*-1+(csum[n-1]-csum[mx2-1])*-1+csum[mx2-1]-csum[mi];
			System.out.println(print);
		}
	}
}


import java.util.*;

public class Solution
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();

		int[] array = new int[n];
		int[] csum=new int[n];

		for(int i=0;i<n;i++)
		{
			array[i]=s.nextInt();
			if(i==0)
				csum[i]=array[i];
			else
				csum[i]=csum[i-1]+array[i];
		}

		int s1=0,s2=0;

		if(n==1)
		{
			System.out.println(array[0]>=0?array[0]:(-1*array[0]));
		}

		if(n%2==0)
		{
			s2=n/2;
			s1=n/2;
		}
		else
		{
			s1=n/2;
			s2=n/2;
			s2++;
		}

		int[] prefix = new int[s1];
		int[] suffix = new int[s2];
		int max=0;
		int mi=-1;

		for(int y=0;y<s1;y++)
		{
			if(y==0)
			{
				prefix[0]=array[0];
				if(prefix[0]<max)
				{
					max=prefix[0];
					mi=0;
				}
			}
			else
			{
				prefix[y]=prefix[y-1]+array[y];
				if(prefix[y]<max)
				{
					max=prefix[y];
					mi=y;
				}
			}
		}
		int max2=0;
		int mx2=-1;
		for(int y=n-1;y>=n-s2;y--)
		{
			if(y==n-1)
			{
				suffix[0]=array[n-1];
				if(suffix[0]<max2)
				{
					max2=suffix[0];
					mx2=y;
				}
			}
			else
			{
				suffix[n-1-y]=suffix[n-1-y-1]+array[y];
				if(suffix[n-1-y]<max2)
				{
					max2=suffix[n-1-y];
					mx2=y;
				}
			}
		}

		if(mi==-1 && mx2==-1)
		{
			System.out.println(csum[n-1]);
		}
		else if(mi==-1)
		{
			int print = csum[mx2-1]+(csum[n-1]-csum[mx2-1])*-1;
			System.out.println(print);
		}
		else if(mx2==-1)
		{
			int print = csum[mi]*-1+(csum[n-1]-csum[mi]);
			System.out.println(print);
		}
		else
		{
			int print = csum[mi]*-1+(csum[n-1]-csum[mx2-1])*-1+csum[mx2-1]-csum[mi];
			System.out.println(print);
		}
	}
}


import java.util.*;

public class main
{
	public static int maxsu(int[] prefix, int ind, int[] array)
	{
		if(ind==prefix.length)
			return 0;
		int min=Integer.MAX_VALUE;
		int i=-1;
		for(int y=ind;y<prefix.length;y++)
		{
			if(prefix[prefix.length-1]-prefix[y-1]<min)
			{
				min=prefix[prefix.length-1]-prefix[y-1];
				i=y;
			}
		}
		if(min<0)
			min=-min;

		for(int p=ind;p<i;p++)
			min+=array[p];
		return min;
	}
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();

		int[] array = new int[n];
		int[] prefix = new int[n];
		int[] suffix = new int[n];
		int max=Integer.MIN_VALUE;
		int mi=-1;
		int min=Integer.MAX_VALUE;
		int mi2=-1;
		for(int y=0;y<n;y++)
		{
			array[y]=s.nextInt();
			if(y!=0)
			{
				prefix[y]=prefix[y-1]+array[y];
			}
			else
			{
				prefix[0]=array[0];
			}
			max=Math.max(max, prefix[y]);
			if(max==prefix[y])
				mi=y;
			min=Math.min(min, prefix[y]);
			if(min==prefix[y])
				mi2=y;
		}
		int temp=0;
		//System.out.println(max+" "+min);
		if(Math.abs(min)>Math.abs(max))
		{
			min=-min;
			temp=min+maxsu(prefix,mi2+1,array);
		}
		else
		{
			temp=max+maxsu(prefix,mi+1,array);
		}
		System.out.println(temp);
	}
}


import java.util.*;

public class main
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();

		int[] array = new int[n];
		//int[] prefix = new int[n];
		//int[] suffix = new int[n];
		int sump=0;
		int temp=0;
		int sp=-1;
		int sums = 0;
		int ss=-1;
		//int sum=0;
		for(int y=0; y<n; y++)
		{
			array[y]=s.nextInt();
			temp+=array[y];
			sump=Math.min(sump, temp);
				if(sump==temp)
					sp=y;
			//sum+=array[y];
			//sum+=array[y];
		}
		//System.out.println(sp);
		if(sump<0)
			sump=-sump;
		temp=0;
		for(int y=n-1;y>=sp+1;y--)
		{
			temp+=array[y];
			sums = Math.min(temp, sums);
			if(sums==temp)
				ss=y;
		}
		int temp1;
		if(sums<0)
			sums=-sums;
		sump+=sums;
		sums=0;
		for(int y=sp+1;y<ss;y++)
		{
			sums+=array[y];
		}
		sump+=sums;
		temp1=sump;
		sums=0;
		ss=-1;
		temp=0;
		sp=0;
		sump=0;
		for(int y=n-1; y>=0; y--)
		{
			//array[y]=s.nextInt();
			temp+=array[y];

				sums=Math.min(sums, temp);
				if(sums==temp)
					ss=y;

			//sum+=array[y];
		}
		if(sums<0)
			sums=-sums;
		temp=0;
		for(int y=0;y<ss;y++)
		{
			temp+=array[y];
			sump = Math.min(temp, sump);
			if(sump==temp)
				sp=y;
		}
		if(sump<0)
			sump=-sump;
		sums+=sump;

		sump=0;
		for(int y=sp+1;y<ss;y++)
		{
			sump+=array[y];
		}
		sums+=sump;
		System.out.println(Math.max(sums, temp1));
	}
}


import java.util.*;

public class Solution
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();

		int[] array = new int[n];
		int[] csum=new int[n];
		int[] maxn=new int[n];
		for(int i=0;i<n;i++)
		{
			array[i]=s.nextInt();
			if(i==0)
			{
				csum[i]=array[i];
				if(csum[i]>=0)
				{
					maxn[i]=0;
				}
				else
					maxn[i]=array[i];
			}
			else
			{
				csum[i]=csum[i-1]+array[i];
				maxn[i]=Math.min(csum[i], maxn[i-1]);
			}
		}

		if(n==1)
		{
			System.out.println(array[0]>=0?array[0]:(-1*array[0]));
			return;
		}
		int maxs=-1;
		for(int y=n-1;y>=0;y--)
		{
			if(y==n-1)
			{
				maxs=Math.max(csum[y]-2*maxn[n-1], maxs);
			}
			else
			{
				maxs=Math.max(maxs, 2*csum[y]-2*maxn[y]-csum[n-1]);
			}
		}
		maxs=Math.max(maxs, -1*csum[n-1]);
		System.out.println(maxs);
	}
}


import java.util.*;

public class Solution
{
	public static void main(String[] args)
	{
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();

		int[] array = new int[n];
		int[] csum=new int[n];

		for(int i=0;i<n;i++)
		{
			array[i]=s.nextInt();
			if(i==0)
				csum[i]=array[i];
			else
				csum[i]=csum[i-1]+array[i];
		}

		int s1=0,s2=0;

		if(n==1)
		{
			System.out.println(array[0]>=0?array[0]:(-1*array[0]));
			return;
		}

		if(n%2==0)
		{
			s2=n/2;
			s1=n/2;
		}
		else
		{
			s1=n/2;
			s2=n/2;
			s2++;
		}

		int[] prefix = new int[s1];
		int[] suffix = new int[s2];
		int max=0;
		int mi=-1;

		for(int y=0;y<s1;y++)
		{
			if(y==0)
			{
				prefix[0]=array[0];
				if(prefix[0]<max)
				{
					max=prefix[0];
					mi=0;
				}
			}
			else
			{
				prefix[y]=prefix[y-1]+array[y];
				if(prefix[y]<max)
				{
					max=prefix[y];
					mi=y;
				}
			}
		}
		int max2=0;
		int mx2=-1;
		for(int y=n-1;y>=n-s2;y--)
		{
			if(y==n-1)
			{
				suffix[0]=array[n-1];
				if(suffix[0]<max2)
				{
					max2=suffix[0];
					mx2=y;
				}
			}
			else
			{
				suffix[n-1-y]=suffix[n-1-y-1]+array[y];
				if(suffix[n-1-y]<max2)
				{
					max2=suffix[n-1-y];
					mx2=y;
				}
			}
		}

		if(mi==-1 && mx2==-1)
		{
			System.out.println(csum[n-1]);
		}
		else if(mi==-1)
		{
			int print = csum[mx2-1]+(csum[n-1]-csum[mx2-1])*-1;
			System.out.println(print);
		}
		else if(mx2==-1)
		{
			int print = csum[mi]*-1+(csum[n-1]-csum[mi]);
			System.out.println(print);
		}
		else
		{
			int print = csum[mi]*-1+(csum[n-1]-csum[mx2-1])*-1+csum[mx2-1]-csum[mi];
			System.out.println(print);
		}
	}
}


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

public class WonderfulRandomizedSum {

	private static long[] num;
	private static long[] prefix;
	private static long[] suffix;

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		num = new long[n];
		prefix = new long[n];
		suffix = new long[n];

		StringTokenizer stk = new StringTokenizer(br.readLine());
		long sum = 0;
		for(int i = 0; stk.hasMoreElements(); i++) {
			num[i] = Long.parseLong(stk.nextToken());
			sum += num[i];
		}

		long posSum = 0;
		long negSum = 0;

		for(int i = 0; i < n; i++) {
			prefix[i] = Math.max(posSum, negSum) + num[i];
			prefix[i] = Math.max(prefix[i], negSum - num[i]);
			if(i > 0)
			prefix[i] = Math.max(prefix[i], prefix[i-1]+num[i]);
			//System.out.print(prefix[i] + " ");
			posSum += num[i];
			negSum -= num[i];
		}

		posSum = 0;
		negSum = 0;
		for(int i = n-1; i >= 0; i--) {
			suffix[i] = Math.max(posSum, negSum) + num[i];
			suffix[i] = Math.max(suffix[i], negSum - num[i]);
			if(i < n-1)
			suffix[i] = Math.max(suffix[i], suffix[i+1] + num[i]);
			//System.out.println(suffix[i] + " ");
			posSum += num[i];
			negSum -= num[i];
		}
		long ans = sum;
		for(int i = 0; i < n-1; i++) {
			ans = Math.max(ans, prefix[i] + suffix[i+1]);
		}
		if(n == 1) {
			System.out.println(Math.max(sum, -sum));
		} else {
			System.out.println(ans);
		}
	}

}


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

public class WonderfulRandomizedSum {

	private static long[] num;
	private static long[] prefix;
	private static long[] suffix;

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		num = new long[n];
		prefix = new long[n];
		suffix = new long[n];

		StringTokenizer stk = new StringTokenizer(br.readLine());
		long sum = 0;
		for(int i = 0; stk.hasMoreElements(); i++) {
			num[i] = Long.parseLong(stk.nextToken());
			sum += num[i];
		}

		long posSum = 0;
		long negSum = 0;

		for(int i = 0; i < n; i++) {
			prefix[i] = Math.max(posSum, negSum) + num[i];
			prefix[i] = Math.max(prefix[i], negSum - num[i]);
			if(i > 0)
			prefix[i] = Math.max(prefix[i], prefix[i-1]+num[i]);
			//System.out.print(prefix[i] + " ");
			posSum += num[i];
			negSum -= num[i];
		}

		posSum = 0;
		negSum = 0;
		for(int i = n-1; i >= 0; i--) {
			suffix[i] = Math.max(posSum, negSum) + num[i];
			suffix[i] = Math.max(suffix[i], negSum - num[i]);
			if(i < n-1)
			suffix[i] = Math.max(suffix[i], suffix[i+1] + num[i]);
			//System.out.println(suffix[i] + " ");
			posSum += num[i];
			negSum -= num[i];
		}
		long ans = sum;
		for(int i = 0; i < n-1; i++) {
			ans = Math.max(ans, prefix[i] + suffix[i+1]);
		}
		System.out.println(ans);
	}

}


/**
 * DA-IICT
 * Author : PARTH PATEL
 */
import java.io.*;
import java.math.*;
import java.util.*;

import static java.util.Arrays.fill;
import static java.lang.Math.*;
import static java.util.Arrays.sort;
import static java.util.Collections.sort;

public class C33 {

	public static long mod = 1000000007;
	public static long INF = (1L << 60);
	static FasterScanner in = new FasterScanner();
	static PrintWriter out = new PrintWriter(System.out);

	public static void main(String[] args) {

		int n=in.nextInt();
		int[] arr=new int[n+1];
		int[] prefixsum=new int[n+2];
		int[] suffixsum=new int[n+2];
		int answer=0;
		for(int i=1;i<=n;i++)
		{
			arr[i]=in.nextInt();
			prefixsum[i]=prefixsum[i-1]+arr[i];
		}
		answer=prefixsum[n];
		for(int i=n;i>=1;i--)
		{
			suffixsum[i]=suffixsum[i+1]+arr[i];
		}
		int[] dp1=new int[n+2];
		int[] dp2=new int[n+2];
		for(int i=1;i<=n;i++)
		{
			dp1[i]=max(dp1[i-1]+arr[i], abs(prefixsum[i]));
		}
		for(int i=n;i>=1;i--)
		{
			dp2[i]=max(dp2[i+1]+arr[i], abs(suffixsum[i]));
		}
		for(int i=1;i<=n;i++)
		{
			answer=max(answer, dp1[i-1]+dp2[i]);
			answer=max(answer, dp1[i]+dp2[i+1]);
		}
		out.println(answer);
		out.close();

	}

	public static long pow(long x, long n, long mod) {
		long res = 1;
		for (long p = x; n > 0; n >>= 1, p = (p * p) % mod) {
			if ((n & 1) != 0) {
				res = (res * p % mod);
			}
		}
		return res;
	}

	public static long gcd(long n1, long n2) {
		long r;
		while (n2 != 0) {
			r = n1 % n2;
			n1 = n2;
			n2 = r;
		}
		return n1;
	}

	public static long lcm(long n1, long n2) {
		long answer = (n1 * n2) / (gcd(n1, n2));
		return answer;
	}

	static class FasterScanner {
		private byte[] buf = new byte[1024];
		private int curChar;
		private int snumChars;

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

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

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

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

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

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

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

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

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

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.stream.Stream;

public class Solution implements Runnable {

	static final long MOD = (long) 1e9 + 7;
	static final Reader in = new Reader();
	static final PrintWriter out = new PrintWriter(System.out);
	StringBuilder answer = new StringBuilder();

	public static void main(String[] args) {
		new Thread(null, new Solution(), "persefone", 1 << 28).start();
	}

	@Override
	public void run() {
		solve(in.nextInt());
		printf();
	}

	void solve(int n) {
		int[] a = in.nextIntArray(n);
		int[] s = new int[n + 1];
		for (int i = 0; i < n; i++)
			s[i + 1] = s[i] + a[i];

		int min = 0, max = 0;

		for (int i = 1; i <= n; i++) {
			max = Math.max(max, s[i] - min);
			min = Math.min(min, s[i]);
		}
		printf(2 * max - s[n]);
	}

	int lw(Node[] node, int l, int r, int k) {

		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
			if (m == R) return m;
			if (node[m].x >= k)
				r = m - 1;
			else
				l = m + 1;
		}
		return l;
	}

	static class cmp implements Comparator<Node> {
		@Override
		public int compare(Node n1, Node n2) {
			return n1.x - n2.x;
		}
	}

	static class Node {
		int x, y;

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

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

	void printf() {
		out.print(answer);
		out.close();
	}

	void printf(Stream<?> str) {
		str.forEach(o -> add(o, " "));
		add("\n");
	}

	void printf(Object... obj) {
		printf(false, obj);
	}

	private void printf(boolean b, Object... obj) {

		if (obj.length > 1) {
			for (int i = 0; i < obj.length; i++) {
				if (b)
					add(obj[i].getClass().getSimpleName(), " - ");
				if (obj[i] instanceof Collection<?>) {
					printf((Collection<?>) obj[i]);
				} else if (obj[i] instanceof Object[]) {
					printf(obj[i]);
				} else
					printf(obj[i]);
			}
			return;
		}

		if (b)
			add(obj[0].getClass().getSimpleName(), " - ");
		printf(obj[0]);
	}

	void printf(Object o) {
		if (o instanceof int[])
			printf(Arrays.stream((int[]) o).boxed());
		else if (o instanceof char[])
			printf(new String((char[]) o));
		else if (o instanceof long[])
			printf(Arrays.stream((long[]) o).boxed());
		else if (o instanceof double[])
			printf(Arrays.stream((double[]) o).boxed());
		else
			add(o, "\n");
	}

	void printf(Collection<?> col) {
		printf(col.stream());
	}

	<T, K> void add(T t, K k) {
		if (t instanceof Collection<?>) {
			((Collection<?>) t).forEach(i -> add(i, " "));
		} else if (t instanceof Object[]) {
			Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
		} else
			add(t);
		add(k);
	}

	<T> void add(T t) {
		answer.append(t);
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T min(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) < 0)
				m = t[i];
		return m;
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T max(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) > 0)
				m = t[i];
		return m;
	}

	static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
			implements Comparable<Pair<K, V>> {
		private K k;
		private V v;

		Pair() {}

		Pair(K k, V v) {
			this.k = k;
			this.v = v;
		}

		K getK() { return k; }

		V getV() { return v; }

		void setK(K k) { this.k = k; }

		void setV(V v) { this.v = v; }

		void setKV(K k, V v) {
			this.k = k;
			this.v = v;
		}

		@SuppressWarnings("unchecked")
		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof Pair)) return false;
			Pair<K, V> p = (Pair<K, V>) o;
			return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
		}

		@Override
		public int hashCode() {
			int hash = 31;
			hash = hash * 89 + k.hashCode();
			hash = hash * 89 + v.hashCode();
			return hash;
		}

		@Override
		public int compareTo(Pair<K, V> pair) {
			return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
		}

		@Override
		public Pair<K, V> clone() {
			return new Pair<K, V>(this.k, this.v);
		}

		@Override
		public String toString() {
			return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
		}
	}

	static class Reader {
		private BufferedReader br;
		private StringTokenizer st;

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

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

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

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.stream.Stream;

public class Solution implements Runnable {

	static final long MOD = (long) 1e9 + 7;
	static final Reader in = new Reader();
	static final PrintWriter out = new PrintWriter(System.out);
	StringBuilder answer = new StringBuilder();

	public static void main(String[] args) {
		new Thread(null, new Solution(), "persefone", 1 << 28).start();
	}

	@Override
	public void run() {
		solve(in.nextInt());
		printf();
	}

	void solve(int n) {
		int[] a = in.nextIntArray(n);

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

	int lw(Node[] node, int l, int r, int k) {

		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
			if (m == R) return m;
			if (node[m].x >= k)
				r = m - 1;
			else
				l = m + 1;
		}
		return l;
	}

	static class cmp implements Comparator<Node> {
		@Override
		public int compare(Node n1, Node n2) {
			return n1.x - n2.x;
		}
	}

	static class Node {
		int x, y;

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

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

	void printf() {
		out.print(answer);
		out.close();
	}

	void printf(Stream<?> str) {
		str.forEach(o -> add(o, " "));
		add("\n");
	}

	void printf(Object... obj) {
		printf(false, obj);
	}

	private void printf(boolean b, Object... obj) {

		if (obj.length > 1) {
			for (int i = 0; i < obj.length; i++) {
				if (b)
					add(obj[i].getClass().getSimpleName(), " - ");
				if (obj[i] instanceof Collection<?>) {
					printf((Collection<?>) obj[i]);
				} else if (obj[i] instanceof Object[]) {
					printf(obj[i]);
				} else
					printf(obj[i]);
			}
			return;
		}

		if (b)
			add(obj[0].getClass().getSimpleName(), " - ");
		printf(obj[0]);
	}

	void printf(Object o) {
		if (o instanceof int[])
			printf(Arrays.stream((int[]) o).boxed());
		else if (o instanceof char[])
			printf(new String((char[]) o));
		else if (o instanceof long[])
			printf(Arrays.stream((long[]) o).boxed());
		else if (o instanceof double[])
			printf(Arrays.stream((double[]) o).boxed());
		else
			add(o, "\n");
	}

	void printf(Collection<?> col) {
		printf(col.stream());
	}

	<T, K> void add(T t, K k) {
		if (t instanceof Collection<?>) {
			((Collection<?>) t).forEach(i -> add(i, " "));
		} else if (t instanceof Object[]) {
			Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
		} else
			add(t);
		add(k);
	}

	<T> void add(T t) {
		answer.append(t);
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T min(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) < 0)
				m = t[i];
		return m;
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T max(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) > 0)
				m = t[i];
		return m;
	}

	static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
			implements Comparable<Pair<K, V>> {
		private K k;
		private V v;

		Pair() {}

		Pair(K k, V v) {
			this.k = k;
			this.v = v;
		}

		K getK() { return k; }

		V getV() { return v; }

		void setK(K k) { this.k = k; }

		void setV(V v) { this.v = v; }

		void setKV(K k, V v) {
			this.k = k;
			this.v = v;
		}

		@SuppressWarnings("unchecked")
		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof Pair)) return false;
			Pair<K, V> p = (Pair<K, V>) o;
			return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
		}

		@Override
		public int hashCode() {
			int hash = 31;
			hash = hash * 89 + k.hashCode();
			hash = hash * 89 + v.hashCode();
			return hash;
		}

		@Override
		public int compareTo(Pair<K, V> pair) {
			return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
		}

		@Override
		public Pair<K, V> clone() {
			return new Pair<K, V>(this.k, this.v);
		}

		@Override
		public String toString() {
			return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
		}
	}

	static class Reader {
		private BufferedReader br;
		private StringTokenizer st;

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

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

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

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Collection;
import java.util.Comparator;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.stream.Stream;

public class Solution implements Runnable {

	static final long MOD = (long) 1e9 + 7;
	static final Reader in = new Reader();
	static final PrintWriter out = new PrintWriter(System.out);
	StringBuilder answer = new StringBuilder();

	public static void main(String[] args) {
		new Thread(null, new Solution(), "persefone", 1 << 28).start();
	}

	@Override
	public void run() {
		solve(in.nextInt());
		printf();
	}

	void solve(int n) {
		int[] a = in.nextIntArray(n);
		int[] s = new int[n + 1];
		for (int i = 0; i < n; i++)
			s[i + 1] = s[i] + a[i];
		TreeSet<Integer> set = new TreeSet<>();
		set.add(0);
		int max = 0;

		for (int i = 1; i <= n; i++) {
			max = Math.max(max, s[i] - set.first());
			set.add(s[i]);
		}
		printf(2 * max - s[n]);
	}

	int lw(Node[] node, int l, int r, int k) {

		int R = r, m = 0;
		while (l <= r) {
			m = l + r >> 1;
			if (m == R) return m;
			if (node[m].x >= k)
				r = m - 1;
			else
				l = m + 1;
		}
		return l;
	}

	static class cmp implements Comparator<Node> {
		@Override
		public int compare(Node n1, Node n2) {
			return n1.x - n2.x;
		}
	}

	static class Node {
		int x, y;

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

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

	void printf() {
		out.print(answer);
		out.close();
	}

	void printf(Stream<?> str) {
		str.forEach(o -> add(o, " "));
		add("\n");
	}

	void printf(Object... obj) {
		printf(false, obj);
	}

	private void printf(boolean b, Object... obj) {

		if (obj.length > 1) {
			for (int i = 0; i < obj.length; i++) {
				if (b)
					add(obj[i].getClass().getSimpleName(), " - ");
				if (obj[i] instanceof Collection<?>) {
					printf((Collection<?>) obj[i]);
				} else if (obj[i] instanceof Object[]) {
					printf(obj[i]);
				} else
					printf(obj[i]);
			}
			return;
		}

		if (b)
			add(obj[0].getClass().getSimpleName(), " - ");
		printf(obj[0]);
	}

	void printf(Object o) {
		if (o instanceof int[])
			printf(Arrays.stream((int[]) o).boxed());
		else if (o instanceof char[])
			printf(new String((char[]) o));
		else if (o instanceof long[])
			printf(Arrays.stream((long[]) o).boxed());
		else if (o instanceof double[])
			printf(Arrays.stream((double[]) o).boxed());
		else
			add(o, "\n");
	}

	void printf(Collection<?> col) {
		printf(col.stream());
	}

	<T, K> void add(T t, K k) {
		if (t instanceof Collection<?>) {
			((Collection<?>) t).forEach(i -> add(i, " "));
		} else if (t instanceof Object[]) {
			Arrays.stream((Object[]) t).forEach(i -> add(i, " "));
		} else
			add(t);
		add(k);
	}

	<T> void add(T t) {
		answer.append(t);
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T min(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) < 0)
				m = t[i];
		return m;
	}

	@SuppressWarnings("unchecked")
	<T extends Comparable<? super T>> T max(T... t) {
		if (t.length == 0)
			return null;
		T m = t[0];
		for (int i = 1; i < t.length; i++)
			if (t[i].compareTo(m) > 0)
				m = t[i];
		return m;
	}

	static class Pair<K extends Comparable<? super K>, V extends Comparable<? super V>>
			implements Comparable<Pair<K, V>> {
		private K k;
		private V v;

		Pair() {}

		Pair(K k, V v) {
			this.k = k;
			this.v = v;
		}

		K getK() { return k; }

		V getV() { return v; }

		void setK(K k) { this.k = k; }

		void setV(V v) { this.v = v; }

		void setKV(K k, V v) {
			this.k = k;
			this.v = v;
		}

		@SuppressWarnings("unchecked")
		@Override
		public boolean equals(Object o) {
			if (this == o) return true;
			if (o == null || !(o instanceof Pair)) return false;
			Pair<K, V> p = (Pair<K, V>) o;
			return k.compareTo(p.k) == 0 && v.compareTo(p.v) == 0;
		}

		@Override
		public int hashCode() {
			int hash = 31;
			hash = hash * 89 + k.hashCode();
			hash = hash * 89 + v.hashCode();
			return hash;
		}

		@Override
		public int compareTo(Pair<K, V> pair) {
			return k.compareTo(pair.k) == 0 ? v.compareTo(pair.v) : k.compareTo(pair.k);
		}

		@Override
		public Pair<K, V> clone() {
			return new Pair<K, V>(this.k, this.v);
		}

		@Override
		public String toString() {
			return String.valueOf(k).concat(" ").concat(String.valueOf(v)).concat("\n");
		}
	}

	static class Reader {
		private BufferedReader br;
		private StringTokenizer st;

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

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

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

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

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

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


import java.util.Scanner;

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


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

@SuppressWarnings("unchecked")
public class Main {
    private static final long MOD = (int)1e9 + 7;

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


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

public class A {

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

		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		int[] a = new int[n];
		int sum = 0;
		for(int i = 0; i < n; ++i)
			sum += a[i] = sc.nextInt();
		int[] suffix = new int[n + 1];
		suffix[n] = 0;
		for(int i = n - 1; i >= 0; --i)
			suffix[i] = suffix[i + 1] - a[i];
		for(int i = n - 1; i >= 0; --i)
			suffix[i] = Math.max(suffix[i], a[i] + suffix[i + 1]);
		int ans = suffix[0];
		sum = 0;
		for(int i = 0; i < n; ++i)
		{
			sum -= a[i];
			ans = Math.max(ans, sum + suffix[i + 1]);
		}
		out.println(ans);
		out.flush();
		out.close();
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

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

		public double nextDouble() throws NumberFormatException, IOException
		{
			return Double.parseDouble(next());
		}

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

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

		public String nextLine() throws IOException {return br.readLine();}

		public boolean ready() throws IOException {return br.ready();}

	}
}


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

public class A {

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

		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		int n = sc.nextInt();
		int[] a = new int[n];

		for(int i = 0; i < n; ++i)
			a[i] = sc.nextInt();
		int[] suffix = new int[n + 1];

		for(int i = n - 1; i >= 0; --i)
			suffix[i] = suffix[i + 1] - a[i];
		for(int i = n - 1; i >= 0; --i)
			suffix[i] = Math.max(suffix[i], a[i] + suffix[i + 1]);
		int ans = suffix[0];
		for(int i = 0, sum = 0; i < n; ++i)
		{
			sum -= a[i];
			ans = Math.max(ans, sum + suffix[i + 1]);
		}
		out.println(ans);
		out.flush();
		out.close();
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){  br = new BufferedReader(new InputStreamReader(s));}

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

		public double nextDouble() throws NumberFormatException, IOException
		{
			return Double.parseDouble(next());
		}

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

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

		public String nextLine() throws IOException {return br.readLine();}

		public boolean ready() throws IOException {return br.ready();}

	}
}


import java.util.Arrays;
import java.util.Scanner;

public class Codeforces33C_Wonderful_Randomized_Sum {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = scanner.nextInt();
        }
        scanner.close();
        int changCount = 1;
        int thisSum = 0;
        int maxSum = 0;
        for (int i = 0; i < n; i++) {
            thisSum+=a[i];
            if(maxSum<thisSum)
                maxSum = thisSum;
            if(thisSum<0)
                thisSum = 0;
        }
        System.out.println(maxSum-(total(a)-maxSum));
    }

    static int total(int[] a){
        int total = 0;
        for (int i: a) {
            total += i ;
        }
        return total;
    }
}


 import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Ds {

	static int[] arr;

	static Long[][] dp;

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

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();

		dp = new Long[n][3];
		arr = new int[n];

		for(int i=0; i<n; i++) {
			arr[i]  = in.nextInt();
		}

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

			for(int j=0; j<3; j++) {

				dp[i][j] = (long) -99999999;
			}
		}

		dp[0][0] = (long) -arr[0];
		dp[0][1] = (long) arr[0];

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

			dp[i][0] = -arr[i] + dp[i-1][0];

			//System.out.println(dp[i][0]);

			dp[i][1] = Math.max(arr[i] + dp[i-1][1], arr[i] + dp[i-1][0]);

		//	System.out.println(dp[i][1]);

			dp[i][2] = Math.max(-arr[i] + dp[i-1][1], -arr[i] + dp[i-1][2]);

		//	System.out.println(dp[i][2]);

		}

		System.out.println(Math.max(Math.max(dp[n-1][0], dp[n-1][1]), dp[n-1][2]) );

	}

}


 import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Ds {

	static int[] arr;

	static Long[][] dp;

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

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();

		dp = new Long[n][3];
		arr = new int[n];

		for(int i=0; i<n; i++) {
			arr[i] = in.nextInt();
		}

		System.out.println(rec(0, 0));
	}

	private static long rec(int i, int part) {

		if(i == arr.length) {
			return 0;
		}
		else if(dp[i][part] != null) {
			return dp[i][part];
		}
		else {

			long ans = 0;

			if(part == 0) {

				ans = Math.max(-arr[i] + rec(i+1, 0), arr[i] + rec(i+1, 1));

			}
			else if(part == 1) {

				ans = Math.max(arr[i] + rec(i+1, 1), -arr[i] + rec(i+1, 2));
			}
			else {

				ans = -arr[i] + rec(i+1, 2);
			}

			return dp[i][part] = ans;
		}
	}

}


import java.util.*;
public class kkl{
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int arr[]=new int[n];
        int sum=0;
        for(int i=0;i<n;i++){
            arr[i]=sc.nextInt();
            sum+=arr[i];
        }
        int max=0,s=0;
        for(int i=0;i<n;i++){
            s+=arr[i];
            if(s<0)
                s=0;
            max=Math.max(max,s);
        }
        System.out.println(2*max-sum);
    }}


import java.io.*;
import java.util.*;
public class Solution
{
    public static void main(String ag[])
    {
        Scanner sc=new Scanner(System.in);
        int i,j,k;
        int N=sc.nextInt();
        int A[]=new int[N+1];
        for(i=1;i<=N;i++)
        A[i]=sc.nextInt();

        int pre[]=new int[N+2];
        int suff[]=new int[N+2];
        int dp1[]=new int[N+2];
        int dp2[]=new int[N+2];

        for(i=1;i<=N;i++)
        pre[i]=pre[i-1]+A[i];

        for(i=N;i>=1;i--)
        suff[i]=suff[i+1]+A[i];

        for(i=1;i<=N;i++)
        dp1[i]=Math.max(dp1[i-1]+A[i],Math.abs(pre[i]));

        for(i=N;i>=1;i--)
        dp2[i]=Math.max(dp2[i+1]+A[i],Math.abs(suff[i]));

        int ans=Integer.MIN_VALUE;
        for(i=1;i<=N;i++)
        ans=Math.max(ans,Math.max(dp1[i-1]+dp2[i],dp1[i]+dp2[i+1]));

        System.out.println(ans);
    }
}


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

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new PrintStream(System.out));
        int n=Integer.parseInt(f.readLine());
        StringTokenizer st=new StringTokenizer(f.readLine());
        int []prefix=new int[n];
        int []arr=new int[n];
        for(int i=0;i<n;i++){
            arr[i]=Integer.parseInt(st.nextToken());
            if(i==0){
                prefix[0]=arr[i];
            }
            else{
                prefix[i]=prefix[i-1]+arr[i];
            }
        }
        int []backwardsprefix=new int[n];
        backwardsprefix[n-1]=arr[n-1];
        for(int i=n-2;i>=0;i--){
            backwardsprefix[i]=backwardsprefix[i+1]+arr[i];
        }
        int low1=Integer.MAX_VALUE;
        int low2=Integer.MAX_VALUE;
        int idx1=0,idx2=n-1;
        for(int i=0;i<n;i++){
            if(low1>prefix[i]){
                low1=prefix[i];
                idx1=i;
            }
        }
        for(int i=n-1;i>idx1;i--){
            if(low2>backwardsprefix[i]){
                low2=backwardsprefix[i];
                idx2=i;
            }
        }
        if(low2==Integer.MAX_VALUE){
            low2=0;
            idx2=n;
        }
        System.out.println(prefix[idx2-1]-prefix[idx1]+(-1*low2)+(-1*low1));
        f.close();
    }
}


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

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new PrintStream(System.out));
        int n=Integer.parseInt(f.readLine());
        int []arr=new int[n];
        int []prefix=new int[n];
        int []backwards=new int[n];
        StringTokenizer st=new StringTokenizer(f.readLine());
        for(int i=0;i<n;i++){
            arr[i]=Integer.parseInt(st.nextToken());
            if(i!=0){
                prefix[i]=prefix[i-1]+arr[i];
            }
            else{
                prefix[i]=arr[0];
            }
        }
        backwards[n-1]=arr[n-1];
        for(int i=n-2;i>=0;i--){
            backwards[i]=backwards[i+1]+arr[i];
        }
        int []dp1=new int[n];
        int []dp2=new int[n];
        dp1[0]=Math.max(arr[0],-1*arr[0]);
        dp2[n-1]=Math.max(arr[n-1],-1*arr[n-1]);
        for(int i=1;i<n;i++){
            dp1[i]=Math.max(dp1[i-1]+arr[i], (-1*arr[i])+(-1*prefix[i-1]));
        }
        for(int i=n-2;i>=0;i--){
            dp2[i]=Math.max(dp2[i+1]+arr[i], (-1*arr[i])+(-1*backwards[i+1]));
        }
        int max=0;
        for(int i=0;i<n-1;i++){
            max=Math.max(max,dp1[i]+dp2[i+1]);
        }
        System.out.println(max);
        f.close();
    }
}
//import java.util.*;
//import java.io.*;
//
//import java.util.*;
//import java.io.*;
//
//public class Main {
//    public static void main(String[] args) throws IOException{
//        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
//        PrintWriter out = new PrintWriter(new PrintStream(System.out));
//        int n=Integer.parseInt(f.readLine());
//        StringTokenizer st=new StringTokenizer(f.readLine());
//        int []prefix=new int[n];
//        int []arr=new int[n];
//        for(int i=0;i<n;i++){
//            arr[i]=Integer.parseInt(st.nextToken());
//            if(i==0){
//                prefix[0]=arr[i];
//            }
//            else{
//                prefix[i]=prefix[i-1]+arr[i];
//            }
//        }
//        int []backwardsprefix=new int[n];
//        backwardsprefix[n-1]=arr[n-1];
//        for(int i=n-2;i>=0;i--){
//            backwardsprefix[i]=backwardsprefix[i+1]+arr[i];
//        }
//        int low1=Integer.MAX_VALUE;
//        int low2=Integer.MAX_VALUE;
//        int idx1=0,idx2=n-1;
//        for(int i=0;i<n;i++){
//            if(low1>prefix[i]){
//                low1=prefix[i];
//                idx1=i;
//            }
//        }
//        for(int i=n-1;i>idx1;i--){
//            if(low2>backwardsprefix[i]){
//                low2=backwardsprefix[i];
//                idx2=i;
//            }
//        }
//        if(low2==Integer.MAX_VALUE){
//            low2=0;
//            idx2=n;
//        }
//        System.out.println(prefix[idx2-1]-prefix[idx1]+(-1*low2)+(-1*low1));
//        f.close();
//    }
//}


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

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

public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new PrintStream(System.out));
        int n=Integer.parseInt(f.readLine());
        int []arr=new int[n];
        int []prefix=new int[n];
        int []backwards=new int[n];
        StringTokenizer st=new StringTokenizer(f.readLine());
        for(int i=0;i<n;i++){
            arr[i]=Integer.parseInt(st.nextToken());
            if(i!=0){
                prefix[i]=prefix[i-1]+arr[i];
            }
            else{
                prefix[i]=arr[0];
            }
        }
        backwards[n-1]=arr[n-1];
        for(int i=n-2;i>=0;i--){
            backwards[i]=backwards[i+1]+arr[i];
        }
        int []dp1=new int[n];
        int []dp2=new int[n];
        dp1[0]=Math.max(arr[0],-1*arr[0]);
        dp2[n-1]=Math.max(arr[n-1],-1*arr[n-1]);
        for(int i=1;i<n;i++){
            dp1[i]=Math.max(dp1[i-1]+arr[i], (-1*arr[i])+(-1*prefix[i-1]));
        }
        for(int i=n-2;i>=0;i--){
            dp2[i]=Math.max(dp2[i+1]+arr[i], (-1*arr[i])+(-1*backwards[i+1]));
        }
        int max=Math.max(dp1[0],dp2[n-1]);
        for(int i=0;i<n-1;i++){
            max=Math.max(max,dp1[i]+dp2[i+1]);
        }
        System.out.println(max);
        f.close();
    }
}
//import java.util.*;
//import java.io.*;
//
//import java.util.*;
//import java.io.*;
//
//public class Main {
//    public static void main(String[] args) throws IOException{
//        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
//        PrintWriter out = new PrintWriter(new PrintStream(System.out));
//        int n=Integer.parseInt(f.readLine());
//        StringTokenizer st=new StringTokenizer(f.readLine());
//        int []prefix=new int[n];
//        int []arr=new int[n];
//        for(int i=0;i<n;i++){
//            arr[i]=Integer.parseInt(st.nextToken());
//            if(i==0){
//                prefix[0]=arr[i];
//            }
//            else{
//                prefix[i]=prefix[i-1]+arr[i];
//            }
//        }
//        int []backwardsprefix=new int[n];
//        backwardsprefix[n-1]=arr[n-1];
//        for(int i=n-2;i>=0;i--){
//            backwardsprefix[i]=backwardsprefix[i+1]+arr[i];
//        }
//        int low1=Integer.MAX_VALUE;
//        int low2=Integer.MAX_VALUE;
//        int idx1=0,idx2=n-1;
//        for(int i=0;i<n;i++){
//            if(low1>prefix[i]){
//                low1=prefix[i];
//                idx1=i;
//            }
//        }
//        for(int i=n-1;i>idx1;i--){
//            if(low2>backwardsprefix[i]){
//                low2=backwardsprefix[i];
//                idx2=i;
//            }
//        }
//        if(low2==Integer.MAX_VALUE){
//            low2=0;
//            idx2=n;
//        }
//        System.out.println(prefix[idx2-1]-prefix[idx1]+(-1*low2)+(-1*low1));
//        f.close();
//    }
//}


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

//java.is.awesome

public class R33CWonderfulSum {

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

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

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

		int sum = suf[0];

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

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

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

		w.println(ans);
		w.close();
	}

	static class InputReader {

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

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

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

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

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

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

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

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

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


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

//java.is.awesome

public class R33CWonderfulSum {

	public static void main(String[] args) {
		InputReader in = new InputReader(System.in);
		PrintWriter w = new PrintWriter(System.out);

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

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

		int sum = suf[0];
		int ans = Math.abs(suf[0]);

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

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

		w.println(ans);
		w.close();
	}

	static class InputReader {

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

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

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

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

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

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

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

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

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


import java.util.*;
import java.io.*;
public class Codeforces33D {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] dp = new int[n];
		int[] o = new int[n];
		int i = 0;
		String[] a = br.readLine().split(" ");
		int sum = 0;
		while(i<n) {
			o[i] = Integer.parseInt(a[i]);
			sum+=o[i];
			dp[i] =  o[i++];
		}
		int cur_max = sum;
		int ind = 0;
		int max = Integer.MIN_VALUE;
		int nneg = 0;
		for(i = 0;i<n;i++){
			int old = sum;
			for(int j = 0;j<i;j++) {
				sum-=2*o[j];
				if(sum>max) {
//					System.out.println(j+" "+1);
					max=sum;
					ind = j;
				}
				if(o[j]<0) {
					nneg++;
				}
			}
			for(int j = n-1;j>ind;j--) {
				sum-=2*o[j];
				if(sum>max) {
//					System.out.println(j+" "+2);
					max=sum;
				}
				if(o[j]<0) {
					nneg++;
				}
			}
			for(int j = ind;j>=0;j--) {
				sum+=2*o[j];
				if(sum>max) {
//					System.out.println(j+" "+3);
					max=sum;
				}
				if(o[j]>0) {
					nneg--;
				}
			}
			if(nneg == n) break;
			cur_max = Math.max(old, max);
			cur_max = (sum<cur_max ? cur_max : sum);
			sum =  old;
			nneg = 0;
		}
		System.out.print(nneg == n ? Math.abs(max) : Math.abs(cur_max));
	}
}


import java.util.*;
import java.io.*;
public class Codeforces33D {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] dp = new int[n];
		int[] o = new int[n];
		int i = 0;
		String[] a = br.readLine().split(" ");
		int sum = 0;
		while(i<n) {
			o[i] = Integer.parseInt(a[i]);
			sum+=o[i];
			dp[i] =  o[i++];
		}
		int cur_max = sum;
		int ind = 0;
		int max = Integer.MIN_VALUE;
		int nneg = 0;
		for(i = 0;i<n;i++){
			int old = sum;
			for(int j = 0;j<i;j++) {
				sum-=2*o[j];
				if(sum>max) {
//					System.out.println(j+" "+1);
					max=sum;
					ind = j;
				}
				if(o[j]<0) {
					nneg++;
				}
			}
			for(int j = n-1;j>ind;j--) {
				sum-=2*o[j];
				if(sum>max) {
//					System.out.println(j+" "+2);
					max=sum;
				}
				if(o[j]<0) {
					nneg++;
				}
			}
			for(int j = ind;j>=0;j--) {
				sum+=2*o[j];
				if(sum>max) {
//					System.out.println(j+" "+3);
					max=sum;
				}
				if(o[j]>0) {
					nneg--;
				}
			}
			if(nneg == n) break;
			cur_max = Math.max(old, max);
			cur_max = (sum<cur_max ? cur_max : sum);
			sum =  old;
			nneg = 0;
		}
		System.out.print(nneg == n ? max : cur_max);
	}
}


import java.util.*;
import java.io.*;
public class Codeforces33D {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] a = br.readLine().split(" ");
		int[] mat = new int[n+1];
		mat[n] = 0;
		int[] sum = new int[n+1];
		for(int i = 0;i<n;i++) {
			mat[i] = Integer.parseInt(a[i]);
			sum[i+1] = sum[i] + mat[i];
		}
		int ans = 0;
		int m = 0;
		for(int i = n;i>=0;i--) {
//			System.out.println(sum[i]+" "+ans);
			m = Math.max(m, sum[i]-sum[n]);
			ans = Math.max(ans, sum[n]-2*sum[i]+2*m);
//			System.out.println(sum[i]+" "+ans+"\n");
		}
		System.out.println(ans);
	}
}


import java.util.*;
import java.io.*;
public class Codeforces33D {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] dp = new int[n];
		int[] o = new int[n];
		int i = 0;
		String[] a = br.readLine().split(" ");
		int sum = 0;
		while(i<n) {
			o[i] = Integer.parseInt(a[i]);
			sum+=o[i];
			dp[i] =  o[i++];
		}
		int cur_max = sum;
		int ind = 0;
		int max = Integer.MIN_VALUE;
		for(i = 0;i<n;i++){
			int old = sum;
			for(int j = 0;j<i;j++) {
				sum-=2*o[j];
				if(sum>max) {
//					System.out.println(j+" "+1);
					max=sum;
					ind = j;
				}
			}
			for(int j = n-1;j>ind;j--) {
				sum-=2*o[j];
				if(sum>max) {
//					System.out.println(j+" "+2);
					max=sum;
				}
			}
			for(int j = ind;j>=0;j--) {
				sum+=2*o[j];
				if(sum>max) {
//					System.out.println(j+" "+3);
					max=sum;
				}
			}
			cur_max = Math.max(sum, max);
			sum = (sum<cur_max ? cur_max : sum);
			sum =  old;
		}
		System.out.print(cur_max);
	}
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.awt.Point;

public class TryB
{

    static class InputReader {

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

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

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

		public int ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

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

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

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

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

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

	}

		static PrintWriter w = new PrintWriter(System.out);
 static char [][]sol;
    public static void main(String[] args)
    {

        InputReader sc = new InputReader(System.in);
        //PrintWriter w = new PrintWriter(System.out);

       /*
        prime  = new boolean[n + 1];
		sieve();
		prime[1] = false;
		*/
		/*
		as = new ArrayList<>();
		for(int i=2;i<=1000000;i++)
		{
		    if(prime[i])
		    as.add(i);
		}
		*/

       /*

	long a = sc.nl();

            BigInteger ans = new BigInteger("1");
            for (long i = 1; i < Math.sqrt(a); i++) {
                if (a % i == 0) {
                    if (a / i == i) {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));

                    } else {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));
                        ans = ans.multiply(BigInteger.valueOf(phi(a / i)));

                    }

                }
            }
            w.println(ans.mod(bigInteger));
            */

         // MergeSort ob = new MergeSort();
       // ob.sort(arr, 0, arr.length-1);

    // Student []st = new Student[x];
   // st[i] = new Student(i,d[i]);
     //Arrays.sort(st,(p,q)->p.diff-q.diff);
int x = sc.ni();
int []a = sc.nia(x);
int sum = 0;
int temp = 0;
int max = 0;
for(int i=0;i<x;i++)
{
    temp += a[i];
    if(temp < 0)
        temp = 0;
    if(temp > max)
        max = temp;
    sum += a[i];
}
w.println(2*max-sum);

     w.close();

    }

    static boolean checkT(int a,int b, int c)
    {
        int f = 0;
        if(a+b <= c || b+c <=a||a+c <= b)
            return false;
        else
            return true;
    }
    static double costheta(int a,int b,int c)
    {
        double pos = ((double)b*(double)b + (double)c*(double)c-(double)a*(double)a) / (2*(double)b*(double)c);
         return pos;
    }
     public static int ip(String s){
		return Integer.parseInt(s);
	}
	 public static String ips(int s){
		return Integer.toString(s);
	}
         static long area(int ax,int ay,int bx,int by,int cx,int cy)
         {
             long ar = ((long)ax*((long)by-(long)cy)) + ((long)bx*((long)cy-(long)ay)) + ((long)cx*((long)ay-(long)by));
             return Math.abs(ar);
         }
         public static int lowerBound(Student[] array, int length, int value) {
        int low = 0;
        int high = length-1;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value <= array[mid].val) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }
        return low;
  }
  public static int upperBound(int[] array, int length, int value) {
        int low = 0;
        int high = length-1;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value >= array[mid]) {
                low = mid + 1;
            } else {
                high = mid;
            }
        }
        return low;
    }
   static class Student
    {

        int val;
        int index;
        Student(int val,int index)
        {
            this.val = val;
            this.index = index;

        }

    }
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.awt.Point;

public class TryB
{

    static class InputReader {

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

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

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

		public int ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

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

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

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

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

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

	}

		static PrintWriter w = new PrintWriter(System.out);
 static char [][]sol;
    public static void main(String[] args)
    {

        InputReader sc = new InputReader(System.in);
        //PrintWriter w = new PrintWriter(System.out);

       /*
        prime  = new boolean[n + 1];
		sieve();
		prime[1] = false;
		*/
		/*
		as = new ArrayList<>();
		for(int i=2;i<=1000000;i++)
		{
		    if(prime[i])
		    as.add(i);
		}
		*/

       /*

	long a = sc.nl();

            BigInteger ans = new BigInteger("1");
            for (long i = 1; i < Math.sqrt(a); i++) {
                if (a % i == 0) {
                    if (a / i == i) {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));

                    } else {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));
                        ans = ans.multiply(BigInteger.valueOf(phi(a / i)));

                    }

                }
            }
            w.println(ans.mod(bigInteger));
            */

         // MergeSort ob = new MergeSort();
       // ob.sort(arr, 0, arr.length-1);

    // Student []st = new Student[x];
   // st[i] = new Student(i,d[i]);
     //Arrays.sort(st,(p,q)->p.diff-q.diff);
 int x = sc.ni();
 int []a = sc.nia(x);
 int f = 0;
 for(int i=0;i<x;i++)
 {
     if(a[i] <= 0 && f==0)
     {
         a[i] *= -1;
         if(i+1 < x && Math.abs(a[i]) < Math.abs(a[i+1]) && !(a[i]*-1 < 0 && a[i+1] < 0))
             f = 1;
     }
     else if(i+1 < x && Math.abs(a[i]) < Math.abs(a[i+1]) && !(a[i] < 0 && a[i+1] < 0))
         f = 1;

 }

 //w.println();
 f = 0;
  for(int i=x-1;i>0;i--)
  {
      if(a[i] < 0 && f==0)
      {
          a[i] *= -1;
          if(Math.abs(a[i]) < Math.abs(a[i-1]) && !(a[i]*-1 < 0 && a[i-1] < 0))
              f = 1;
      }

      else if(Math.abs(a[i]) < Math.abs(a[i-1]) && !(a[i] < 0 && a[i-1] < 0))
         f = 1;

  }
  long sum = 0;
  for(int i=0;i<x;i++)
  {
      sum += (long) a[i];
      //w.print(a[i] + " ");
  }
  w.println(sum);

     w.close();

    }

    static boolean checkT(int a,int b, int c)
    {
        int f = 0;
        if(a+b <= c || b+c <=a||a+c <= b)
            return false;
        else
            return true;
    }
    static double costheta(int a,int b,int c)
    {
        double pos = ((double)b*(double)b + (double)c*(double)c-(double)a*(double)a) / (2*(double)b*(double)c);
         return pos;
    }
     public static int ip(String s){
		return Integer.parseInt(s);
	}
	 public static String ips(int s){
		return Integer.toString(s);
	}
         static long area(int ax,int ay,int bx,int by,int cx,int cy)
         {
             long ar = ((long)ax*((long)by-(long)cy)) + ((long)bx*((long)cy-(long)ay)) + ((long)cx*((long)ay-(long)by));
             return Math.abs(ar);
         }
         public static int lowerBound(Student[] array, int length, int value) {
        int low = 0;
        int high = length-1;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value <= array[mid].val) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }
        return low;
  }
  public static int upperBound(int[] array, int length, int value) {
        int low = 0;
        int high = length-1;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value >= array[mid]) {
                low = mid + 1;
            } else {
                high = mid;
            }
        }
        return low;
    }
   static class Student
    {

        int val;
        int index;
        Student(int val,int index)
        {
            this.val = val;
            this.index = index;

        }

    }
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
import java.awt.Point;

public class TryB
{

    static class InputReader {

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

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

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

		public int ni() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nl() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

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

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

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

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

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

	}

		static PrintWriter w = new PrintWriter(System.out);
 static char [][]sol;
    public static void main(String[] args)
    {

        InputReader sc = new InputReader(System.in);
        //PrintWriter w = new PrintWriter(System.out);

       /*
        prime  = new boolean[n + 1];
		sieve();
		prime[1] = false;
		*/
		/*
		as = new ArrayList<>();
		for(int i=2;i<=1000000;i++)
		{
		    if(prime[i])
		    as.add(i);
		}
		*/

       /*

	long a = sc.nl();

            BigInteger ans = new BigInteger("1");
            for (long i = 1; i < Math.sqrt(a); i++) {
                if (a % i == 0) {
                    if (a / i == i) {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));

                    } else {
                        ans = ans.multiply(BigInteger.valueOf(phi(i)));
                        ans = ans.multiply(BigInteger.valueOf(phi(a / i)));

                    }

                }
            }
            w.println(ans.mod(bigInteger));
            */

         // MergeSort ob = new MergeSort();
       // ob.sort(arr, 0, arr.length-1);

    // Student []st = new Student[x];
   // st[i] = new Student(i,d[i]);
     //Arrays.sort(st,(p,q)->p.diff-q.diff);
 int x = sc.ni();
 int []a = sc.nia(x);
 int f = 0;
 for(int i=0;i<x;i++)
 {
     if(a[i] <= 0 && f==0)
     {
         a[i] *= -1;
         if(i+1 < x && Math.abs(a[i]) < Math.abs(a[i+1]) && (a[i] > 0 || a[i+1] > 0))
             f = 1;
     }
     else if(i+1 < x && Math.abs(a[i]) < Math.abs(a[i+1]) && (a[i] > 0 || a[i+1] > 0))
         f = 1;

 }

 //w.println();
 f = 0;
  for(int i=x-1;i>0;i--)
  {
      if(a[i] < 0 && f==0)
      {
          a[i] *= -1;
          if(Math.abs(a[i]) < Math.abs(a[i-1]) && (a[i] > 0 || a[i-1] > 0))
              f = 1;
      }

      else if(Math.abs(a[i]) < Math.abs(a[i-1]) && (a[i] > 0 || a[i-1] > 0))
         f = 1;

  }
  long sum = 0;
  for(int i=0;i<x;i++)
  {
      sum += (long) a[i];
     // w.print(a[i] + " ");
  }
  w.println(sum);

     w.close();

    }

    static boolean checkT(int a,int b, int c)
    {
        int f = 0;
        if(a+b <= c || b+c <=a||a+c <= b)
            return false;
        else
            return true;
    }
    static double costheta(int a,int b,int c)
    {
        double pos = ((double)b*(double)b + (double)c*(double)c-(double)a*(double)a) / (2*(double)b*(double)c);
         return pos;
    }
     public static int ip(String s){
		return Integer.parseInt(s);
	}
	 public static String ips(int s){
		return Integer.toString(s);
	}
         static long area(int ax,int ay,int bx,int by,int cx,int cy)
         {
             long ar = ((long)ax*((long)by-(long)cy)) + ((long)bx*((long)cy-(long)ay)) + ((long)cx*((long)ay-(long)by));
             return Math.abs(ar);
         }
         public static int lowerBound(Student[] array, int length, int value) {
        int low = 0;
        int high = length-1;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value <= array[mid].val) {
                high = mid;
            } else {
                low = mid + 1;
            }
        }
        return low;
  }
  public static int upperBound(int[] array, int length, int value) {
        int low = 0;
        int high = length-1;
        while (low < high) {
            final int mid = (low + high) / 2;
            if (value >= array[mid]) {
                low = mid + 1;
            } else {
                high = mid;
            }
        }
        return low;
    }
   static class Student
    {

        int val;
        int index;
        Student(int val,int index)
        {
            this.val = val;
            this.index = index;

        }

    }
}


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

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);

		int n = in.nextInt(), sum = 0, Sum = 0, Max = 0;
		Integer[] a = new Integer[n];
		for (int i = 0; i < n; ++i) {
			a[i] = in.nextInt();
			sum += a[i];
		}
		for (int i = 0; i < n; ++i) {
			if (Sum + a[i] < 0) Sum = 0;
			else {
				Sum += a[i];
				Max = Math.max(Max, Sum);
			}
		}
		int ans = 2 * Max - sum;
		System.out.println(ans);
	}
}