#include <iostream>

int calcMaxSum(int amount_set);

int main()
{
    while (true) {
        int amount_set;
        std::cin >> amount_set;
        
        if(amount_set == 0) {
            break;
        }
        std::cout << calcMaxSum(amount_set) << std::endl;
    }

    return 0;
}

int calcMaxSum(int amount_set)
{
    const int MAXNUMBER = 100000;//??\????????????????????§??????

    int *data;
    data = new int[amount_set];
    int sum = 0;
    int max = -amount_set * MAXNUMBER;//??????????????????????°?????????§????????????int?????\??????
    int min = 0;//?????????min?????£?????????????????????????????????????????°???????????§???min???0????????????

    for (int number = 0; number < amount_set; number++) {
        std::cin >> data[number];//????????????????????????
        sum += data[number];// ????????´??°

        if (sum > max) {//?????§?????????????????§????????£??????
            max = sum;//?????§????????´??°
        } 
        if (sum < min) {//????°?????????????????°?????????£??????
            min = sum;//????°?????????´??°
        }
    }

    delete [] data;

    return max - min;

}