package test;
import java.util.*;
public class Array {
public static void main(String []args) {
int [] A= {1,-2,3,5,6};
int max=0;
int a,b;
b=getCount(A)-getMin(A);
a=getMax(A);
if(a>b) {
System.out.println(a);
}else {
System.out.println(b);
}
}
public static int getMax(int [] a) {
int []b=new int[a.length];
System.arraycopy(a, 0, b, 0, a.length);
for(int i=1;i<a.length;i++) {
if(b[i]+b[i-1]>b[i]) {
b[i]+=b[i-1];
}
}
int max=0;
for(int i=0;i<b.length;i++) {
if(max<b[i]) {
max=b[i];
}
}
return max;
}
public static int getMin(int [] a) {
int []b=new int[a.length];
System.arraycopy(a, 0, b, 0, a.length);
for(int i=1;i<a.length;i++) {
if(b[i]+b[i-1]<b[i]) {
b[i]+=b[i-1];
}
}
int min=0;
for(int i=0;i<b.length;i++) {
if(min>b[i]) {
min=b[i];
}
}
return min;
}
public static int getCount(int [] a) {
int count=0;
for(int i=0;i<a.length;i++) {
count+=a[i];
}
return count;
}
}