#include <stdio.h>
#include<malloc.h>

int main() {
    int n, i, j, sum, max;
    scanf("%d", &n);
    int* arr = (int*)malloc(100000 * sizeof(int));
    for (i = 0; i < n; i++)
        scanf("%d", &arr[i]);

    max = arr[0];
    sum = 0;

    for (i = 0; i < n; i++) {
        if (sum < 0)
            sum = arr[i];
        else
            sum += arr[i];
        if (sum > max)
            max = sum;

    }
    printf("%d\n", max);
    free(arr);

}