import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.io.InputStreamReader;
public class Main {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
int[] arr = new int[N];
int max = Integer.MIN_VALUE ;
for(int i = 0 ; i < N ; i ++) {
arr[i] = Integer.parseInt(st.nextToken());
}
int cum = 0 ;
for(int i = 0 ; i <N ; i ++) {
if(cum < 0) {
cum = 0;
}
cum+=arr[i];
if(max < cum) max = cum;
}
System.out.println(max);
}
}