class solver:
    def __init__(self):
        self.v_ = []
        self.n = 0

    def read_input(self):
        self.n = int(input())
        self.v_ = list(map(int, input().split()))

    def solve(self):
        (v, n) = self.v_, self.n
        dp = [ x for x in v]
        for i in range(1, n):
            dp[i] = max(dp[i-1] + v[i], dp[i])
        ans = max(dp)
        print(ans)
    
def main()->None: 
    s = solver()
    s.read_input()
    s.solve()

if __name__ == "__main__":
    main()