
N = int(input())
A = [input() for i in range(N)]

# S = sorted(A)
# MAXS = max(A)
# two = S[-2]
# print("MAX {} two {}".format(MAXS,two))
# count = S.count(max(S))
#
# for i in range(N):
#     if A[i] == MAXS:
#         if count > 1:
#             print(MAXS)
#         else:
#             print(two)
#     else:
#         print(MAXS)

index = A.index(max(A))
MAXS = max(A)
A.sort()
two = A[-2]

for i in range(N):
    if i == index:
        print(two)
    else:
        print(MAXS)