n = int(input()) v = list(map(int, input().split())) dp=list() dp.append(0) dp.append(v[0]) for i in range(1,n): dp.append(max(dp[i-1]+v[i],dp[i])) print(dp[-1])