#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
  int n;
  while (cin >> n) {
    if (n == 0)
      break;
    vector<int> a(n, 0); //?´??????¨
    vector<int> b(n, 0); //????????¨
    int s = 0; //?????????????????????????????¨
    for (int i = 0; i < n; i++) {
      cin >> a[i];
      b[i] = a[i];
    }
    int k = n - 1;
    while (a[k] < 0)
      k--;
    for (int i = k - 1; i > -1; i--) {
      if (a[i] < 0)
	continue;
      else {
	int j = i;
	while (a[j] < 0) {
	  s += a[j];
	  j++;
	}
	if (s + b[j] >= 0)
	  b[i] += s + b[j + 1];
	else if (a[i] > s + b[j + 1])
	  b[i] += a[i];
      }
    }
    for (int i = 0; i < n; i++)
      cout << b[i] << endl;
    sort(b.begin(), b.end());
    cout << b[n - 1] << endl;
  }
}