N = int(input())
A = [int(input()) for _ in range(N)]
#print(A)
max_index = set([i for i, x in enumerate(A) if x == max(A)])
f = max(A)
A_sort = sorted(A, reverse=True)
A_list=list(set(A_sort))
if len(A_list) != 1:
    s = A_list[1]
else:
    s = f

l = len(max_index)
#print(max_index)
for i in range(N):
    if i in max_index and l-1==0:
        print(s)
    else:
        print(f)