n = int(input())
a = [*map(int,input().split())]
ans = []
if(n==1):
print(a[0])
exit(0)
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)
elif(a[-1]<0):
if(n==2):
print(a[-1]+a[0])
else:
b = [a[0]+a[-1],sum(a[i] for i in range(1,n-1))]
if (a[0] > b[0] + b[1]):
print(b[0] + b[1])
else:
print(*b)
else:
s = sorted(a)
d = dict()
ds = dict()
ele = -1
for i in range(n):
d[a[i]] = i
for i in range(n):
ds[s[i]] = i
for i in range(n):
if(d[s[i]]!=i):
ele = s[i]
break
if(ele==-1):
print(*a)
exit(0)
b = [a[i] for i in range(ds[ele])]
b += [ele]
x = sum(b)
b += [sum(a[i] for i in range(n))-x]
for i in b:
if(i!=0):
print(i,end =" ")
Copy