input();a=list(map(int,input().split())) b=sorted(a) if b[-1]>a[-1]:b[-2:]=b[-1:-3:-1] print(*b)