while True:#dp思想
    try:
        n = int(input())
        num = list(map(int, input().split(' ')))
        dp = [0 for i in range(n)]
        dp[0] = num[0]
        for i in range(1, n):
            dp[i] = max(num[i], dp[i - 1] + num[i])#dp的含义是末尾为i的最大值
        print(max(dp))
    except:
        break