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

int main(){
	int n, k;
	vector<int> dp;
	cin >> n;

	for(int i = 0; i < n; i++){
		cin >> k;

		if(i == 0)
			dp.push_back(k);
		else
			dp.push_back(max(dp[i -1] + k, k));
	}
	int max = dp[0];
	for(int i = 0; i < n; i++){
		if(max < dp[i]){
			max = dp[i];
		}
	}
	cout << max << endl;
}