#include <bits/stdc++.h>
using namespace std;
int main() {
int size, num; cin >> size;
vector<int> numVec(size), accSum(size);
for (int i=0; i<size; i++) {
cin >> num;
numVec[i] = num;
}
accSum[0] = numVec[0];
int maxNum = numVec[0];
for (int i=1; i<size; i++) {
if ( accSum[i-1] >= 0 ) {
accSum[i] = accSum[i-1] + numVec[i];
} else {
accSum[i] = numVec[i];
}
maxNum = max(maxNum, accSum[i]);
}
cout << maxNum;
return 0;
}