import sys n = int(input()) lis = list(map(int,input().split())) # max_value = sum_value = lis[0] # for x in lis[1:]: # sum_value = max(x,sum_value+x) # if sum_value>max_value: # max_value = sum_value # print(max_value) dp = [0] * n dp[0] = lis[0] for i in range(1,n): dp[i] = max(dp[i-1]+lis[i], lis[i]) print(max(dp))