input()
A = list(map(int, input().split()))

B = sorted(A)

if B[-1] > A[-1]:
    B[-2:] = B[-1:-3:-1]

print(*B)