N = int(input())
A = []

for _ in range(N):
    A.append(input())

max_list = sorted(A, reverse=True)
max_index = A.index(max(A))

for i in range(0, len(A)):
    if i == max_index:
        print(max_list[1])
    else:
        print(max_list[0])