n = int(input())
a = [*map(int,input().split())]
ans = []
if(any(i<0 for i in a)):
b = [sum(i for i in a if i<0),sum(i for i in a if(i>0))]
if(a[0]>b[0]+b[1]):
print(b[0]+b[1])
else:
print(*b)
else:
for i in range(len(a)-1):
# print(a[i])
if a[i] > a[i+1]:
a[-1] += a[i]
# print(a[-1])
else:
# print('yes')
ans.append(a[i])
ans.append(a[-1])
print(*ans)