#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    int t;
    cin >> t;
    int z_max = t,c_max = t; 
    for (int i = 1; i < n; i++) {
        cin >> t;
        c_max = max(t, c_max + t);
        z_max = max(z_max, c_max);
    }
    cout << z_max;
    return 0;
}