# 入力
N = int(input())
A = list(map(int, input().split()))

# 初期化
sum = 0
addmax = 0
now = 0
ans = 0

# for
for i in A:
    sum += i
    if (sum > addmax):
        addmax = sum

    if (now + addmax > ans):
        ans = now + addmax

    now += sum
print(ans)
d9ef5c74520671f75bd344282beb488bfe048431
<mask token>

<mask token>
for i in A:
    sum += i
    if sum > addmax:
        addmax = sum
    if now + addmax > ans:
        ans = now + addmax
    now += sum
print(ans)

N = int(input())
A = list(map(int, input().split()))
sum = 0
addmax = 0
now = 0
ans = 0
for i in A:
    sum += i
    if sum > addmax:
        addmax = sum
    if now + addmax > ans:
        ans = now + addmax
    now += sum
print(ans)

# 入力
N = int(input())
A = list(map(int, input().split()))

# 初期化
sum = 0
addmax = 0
now = 0
ans = 0

# for
for i in A:
    sum += i
    if (sum > addmax):
        addmax = sum

    if (now + addmax > ans):
        ans = now + addmax

    now += sum
print(ans)