while True:
    try:
        n = int(input())
        nums = list(map(int, input().split()))
        pre, Max = 0, nums[0]
        for n in nums:
            pre = max(pre + n, n)
            Max = max(pre, Max)
        print(Max)
    except:
        break