#include <iostream>
#include <algorithm> 
#include <string.h>
using namespace std;

const int N = 1e6 + 10;

long long a[N];
int n;

long long getmax(long long a[],int n){
	long long answer = -100000;
	for(int i = 0;i < n;i ++){
		a[i] = max(a[i],a[i] + a[i - 1]);
		answer = max(answer,a[i]);
	}
	return answer;
}

int main(){
	while(cin >> n){
		memset(a,0,sizeof(a));
		for(int i = 0;i < n;i ++)cin >> a[i];
		long long maxn = getmax(a,n);
		cout << maxn << endl;
	}
	return 0;
}