def lianxu(a):
    size = len(a)
    pre = 0 
    res = a[0]
    for i in range(size):
        pre = max(a[i],pre+a[i])
        res = max(res,pre)
    return res    
    
    
    


n = int(input())
nums = list(map(int,input().split()))

res = lianxu(nums)
print(res)