n = int(input())
a = [int(input()) for _ in range(n)]
a_max_index = [i for i,x in enumerate(a) if x == max(a)] 

if len(set(a)) == 1:
    a_second = a[1]
else:
    a_second = sorted(set(a))[-2]
for i in range(n):
    if i in a_max_index:
        print(a_second)
    else:
        print(max(a))

