#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main(void) {
int n;
cin >> n;
int currsum = -1;
int maxsum = -1;
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
currsum = max(x, x+currsum);
maxsum = max(maxsum, currsum);
}
cout << maxsum;
}