using System;
using System.Collections.Generic;
using System.Linq;

class Program {

    static int Main(string[] args) {
        List<int> inList = new List<int>();

        while (true) {
            string v = Console.ReadLine();
            if (v == "0") { break; }

            inList.Add(int.Parse(v));
        }

        for (int x = 0; x < inList.Count; x++) {
            int n = inList[x];

            List<int> list = new List<int>();
            for (int i = 0; i < n; i++) {
                x++;
                list.Add(inList[x]);
            }

            int maxValue = 0;
            for (int i = 0; i < list.Count; i++) {
                int value = list[i];
                if (maxValue < value) { maxValue = value; }

                for (int k = i + 1; k < list.Count; k++) {
                    value += list[k];
                    if (maxValue < value) { maxValue = value; }
                }
            }

            Console.WriteLine(maxValue);
        }

        return 0;
    }
}

