#include <stdio.h>

int main()
{
        int n, i, j, k;
        double a[5000], sum, max;

        while (scanf("%d", &n) && n != 0) {
                for (i = 0; i < n; i++)
                       scanf("%d", &a[i]);

                max = 0;
                for (j = 0; j < n; j++) {
                        sum = 0;
                        for (i = j; i < n; i++) {
                                sum += a[i];
                                if (sum > max) {
                                        max = sum;
                                }
                        }
                }
                printf("%d\n", max);
        }
        return 0;
}