n = int(input())
a = [*map(int,input().split())]
ans = []
if(any(i<0 for i in a[:-1])):
b = [sum(i for i in a[:-1] if i<0),a[-1]+sum(i for i in a[:-1] if(i>0))]
if(a[0]>b[0]+b[1]):
print(b[0]+b[1])
else:
print(*b)
else:
o = min(a)
ind = 0
while ind < n-1:
if a.index(o) != 0:
for i in a[ind:a.index(o)]:
a[-1] += i
ind += 1
ind += 1
ans.append(o)
o = min(a[a.index(o)+1:])
ans.append(a[-1])
print(*ans)