N = int(input())
s = [int(input()) for i in range(N)]
ld = sorted(s, reverse=True)
print(ld)
D = int(s.index(ld[0]))

if N == 1:
    print(s[0])
else:
    for i in range(D):
        print(ld[0])
    print(ld[1])
    for i in range(N-D-1):
        print(ld[0])