N = int(input())
A = [int(input()) for _ in range(N)]
B = list(set(A))

max_v = max(A)
max_c = A.count(max_v)
for i in range(N):
    tmp = A[i]
    if tmp != max_v:
        print(max_v)
    else:
        if max_c > 1:
            print(max_v)
        else:
            print(B[-2])
