#include <iostream>
#include <algorithm>
#include <climits>

using namespace std;


int main(void) {
    int n;

    while (std::cin >> n) {
        if (n == 0) {
            break;
        }

        int s = 0;
        int max_sum = INT_MIN;
        int min_sum = 0;

        for (int i = 0; i < n; i++) {
            int a;
            cin >> a;

            s += a;

            max_sum = max(max_sum, s - min_sum);
            min_sum = min(min_sum, s);
        }

        std::cout << max_sum << std::endl;
    }

    return 0;
}