#include <iostream>
#include <climits>
#include <numeric>
int main()
{
  while (1) {
    int n;
    std::cin >> n;
    if (n == 0) break;
    int max = -INT_MAX;
    int a[n];
    for (int i = 0;i < n; i++) {
      std::cin >> a[i];
    }
    for (int i  = 0; i < n; i++) {
      if (a[i] < 0) continue;
      for (int j = i + 1; j <= n; j++) {
        int temp = std::accumulate(a + i, a + j, 0);
        if (temp > max) max = temp;
      }
    }
    std::cout << max << std::endl;
  }
}