n = int(input())
a = [*map(int,input().split())]
b = []
i = 0
while(i<n):
mini = 0
if(i<n and a[i]>0):
b.append(a[i])
i+=1
if(i<n and a[i]==0):
i+=1
while(i<n and a[i]<0):
mini += a[i]
i+=1
if(mini!=0):
b.append(mini)
c = []
last = 0
for i in range(len(b)-1):
if(a[i]==b[i] and b[i+1]<0):
c.append(b[i]+b[i+1])
last = i+2
break
else:
c.append(b[i])
if(last<len(b)):
c.append(sum(b[last:]))
d = []
last = 0
for i in range(len(c)-1):
if(c[i]+c[i+1]<a[i]):
d.append(c[i]+c[i+1])
last = i+2
break
elif(c[i]!=0):
d.append(c[i])
last = i+1
if(last<len(c)):
if(len(c[last:])==1):
d.append(c[last])
else:
d+= c[last:]
print(*d)
Copy