def max_subarray_sum(arr):
    if not arr:
        return 0

    cur_sum = max_sum = arr[0]

    for num in arr[1:]:
        cur_sum = max(num, cur_sum + num)
        max_sum = max(max_sum, cur_sum)

    return max_sum

# 输入部分(假设通过input()函数获取)
n = int(input())
nums = list(map(int, input().split()))

result = max_subarray_sum(nums)
print(result)