import sys
n = int(input())
a = []
count = [0 for _ in range(2000001)]

for i in range(n):
    next = int(sys.stdin.readline())
    a.append(next)
    count[next]+=1
start = 0
for i in range(20000,0,-1):
    if count[i]>0:
        v1=i
        count[i]-=1
        start = i
        break
for i in range(start,0,-1):
    if count[i]>0:
        v2=i
        count[i]-=1
        start = i
        break
count[v1]+=1
count[v2]+=1
if count[v1]>1:
    for i in range(n):
        sys.stdout.write('{}\n'.format(v1))
else:
    for v in a:
        if v != v1:
            sys.stdout.write('{}\n'.format(v1))
        else:
            sys.stdout.write('{}\n'.format(v2))


