import sys
n= int(input())
a =[int(input()) for i in range (n)]

maxIndex = [i for i, x in enumerate(a) if x == max(a)]
if len(maxIndex)>=2:
    for i in range(n):
        print(max(a))
else:
    z = int(maxIndex[0])
    s = max(a[0:z],a[z+1:n+1])
    for k in range(z):
            print(max(a))
    print(s[0])
    for k2 in range (n-z-1):
        print(max(a))

