import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, *a = map(int, read().split())

set_a =  sorted(set(a))
if len(set_a) == 1:
    l = [set_a[-1]]*n
    print(*l)
    exit()
max_1 = set_a[-1]
max_2 = set_a[-2]
l = [max_2 if x == max_1 else max_1 for x in a]
print(*l)