#include <stdio.h>
int arr[] = int[5000];
int sub[] = int[5001];
int main() {
  while(1) {
    int n;
    scanf("%d", &n);
    if (n == 0) {
      return 0;
    }
    for(int i = 0; i < n; ++i) {
      scanf("%d", &arr[i]);
    }
    sub[0] = 0;
    for(int i = 1; i < n+1; ++i) {
      sub[i] = sub[i-1] + arr[i-1];
    }
    for(int i = 0; i < n; ++i) { 
        for(int j = i + 1; j < n + 1; ++j) {
          m = max(m, sub[j] - arr[i]);
        }
    }
    printf("%d", m);
  }
}