import math

N = int(input())
s = [input() for i in range(N)]
sinit = s[0]
t = s[:]
t.pop(0)
smax = max(t)
if sinit>=smax:
    print(smax)
    for i in range(N-1):
        print(sinit)

else:
    D = int(s.index(smax))
    x = s[:]
    x.pop(D)
    xmax = max(x)
    for i in range(D):
        print(smax)
    print(xmax)
    for i in range(N-D-1):
        print(smax)
