
#include<iostream>

using namespace std;

int main() {
  int a[5000], n, i, j, result, tmp;
  while(cin >> n && n) {
    for(i = 0; i < n; i++) cin >> a[i];
    for(i = 1; i < n; i++) a[i] += a[i-1];
    result = a[n-1];
    for(i = 0; i < n-1; i++)
      for(j = i+1; j < n; j++)
	if ((tmp = a[j] - a[i]) > result) result = tmp;
    cout << result << endl;
  }
  return 0;
}