n = int(input())
zyski = [int(input()) for i in range(n)]
maks_zysk = 0
biezaca_suma = 0
for zysk in zyski:
biezaca_suma += zysk
if biezaca_suma < 0:
biezaca_suma = 0
maks_zysk = max(maks_zysk, biezaca_suma)
print(maks_zysk)
biA9IGludChpbnB1dCgpKQp6eXNraSA9IFtpbnQoaW5wdXQoKSkgZm9yIGkgaW4gcmFuZ2UobildCgptYWtzX3p5c2sgPSAwIApiaWV6YWNhX3N1bWEgPSAwCgpmb3IgenlzayBpbiB6eXNraToKICAgIGJpZXphY2Ffc3VtYSArPSB6eXNrCiAgICBpZiBiaWV6YWNhX3N1bWEgPCAwOgogICAgICAgIGJpZXphY2Ffc3VtYSA9IDAKICAgIG1ha3NfenlzayA9IG1heChtYWtzX3p5c2ssIGJpZXphY2Ffc3VtYSkKCnByaW50KG1ha3NfenlzaykK