import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
if (scanner.hasNextInt()) {
int N = scanner.nextInt();
int[] arr = new int[N];
for (int i = 0; i < N && scanner.hasNextInt(); i++) {
arr[i] = scanner.nextInt();
}
System.out.println(maxSubarraySum(arr, N));
} else {
System.out.println("No input provided.");
}
scanner.close();
}
public static int maxSubarraySum(int[] arr, int n) {
if (n == 0) return 0;
int maxSum = Integer.MIN_VALUE;
int sum = 0;
for (int i = 0; i < n; i++) {
if(sum<0){
sum=0;
}
sum=sum+arr[i];
if(sum>maxSum){
maxSum=sum;
}
}
return maxSum;
}
}