
import std.stdio, std.algorithm;

void main() {
  for(int t; readf("%d\n", &t), t != 0;) {
    int[] dp = new int[](t);
    int ans = int.min;
    for(int n, i = 0; i < t; i++) {
      readf("%d\n", &n);
      if (i == 0) dp[i] = n;
      else dp[i] = max(n + dp[i - 1], dp[i]);
      ans = max(ans, dp[i]);
    }
    writeln(ans);
  }
}