#include <iostream>
#include <vector>
#include <limits>
using namespace std;


int main()
{
    for (int n; cin >> n && n;) {
        vector<int> sequence(n);
        int sum = 0;
        int min = 0;
        int min_buffer = 0;
        int max = numeric_limits<int>::min();
        for (int x, i = 0; i < n && cin >> x; i++) {
            sum += x;
            if (sum < min)
                min_buffer = sum;
            if (sum > max) {
                max = sum;
                min = min_buffer;
            }
        }
        cout << max - min << endl;
    }

    return 0;
}