#include <iostream>
#define INF 1000000

using namespace std;

const int MAXN = 1e6;
long long dp[MAXN];
long long arr[MAXN];

long long MaxSequence (int n){
	long long maxium = -INF;
	for (int i = 0; i < n; i++){
		if (i == 0){
			dp[i] = arr[i];
		}else{
			dp[i] = max(arr[i], dp[i - 1] + arr[i]);
		}
		maxium = max(dp[i], maxium);
	}
	return maxium;
}
int main () {
	int n; 
	while(cin >> n){
		for (int i = 0; i < n; i++){
			cin >> arr[i];
		}
		cout << MaxSequence(n) << endl;
	}
	return 0;
}

王道那学的