n=int(input())
l=list(map(int,input().split()))
if l[n-1]==max(l): x=0
else: x=1
l=sorted(l)
if x: l[n-2],l[n-1]=l[n-1],l[n-2]
print(*l)