import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner=new Scanner(System.in);
int n=scanner.nextInt();
int[] s=new int[n];
int[] sum=new int[n];
int a;
int max=0;
int min=0;
for(int i=0;i<n;i++){
s[i]=scanner.nextInt();
if(i==0){
min=s[0];
max=s[0];
sum[i]=s[0];
}else{
sum[i]=sum[i-1]+s[i];
a=Integer.max(sum[i], sum[i]-min);
max=Integer.max(a, max);
min=Integer.min(min, sum[i]);
}
}
System.out.println(max);
}
}