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