import collections
N = int(input())
A = [int(input()) for i in range(N)]
set_A = list(set(A))
set_A.sort(reverse=True)
c = collections.Counter(A)
Max = max(A)
Max_list = [i for i, v in enumerate(A) if v == max(A)]
for i in range(N):
    if A[i] == Max:
            if len(Max_list) > 1:
                print(A[i])
            else:
                print(set_A[1])
    else:
        print(Max)
