
n = int(input())
a = list(map(int, input().split()))

# 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)

#


c = a.index(max(a))
m = max(a)
a.sort()
d = a[-2]
for i in range(n):
    if i == c:
        print(d)
    else:
        print(m)




# S = sorted(A)
# MAXS = max(A)
#
# for i in range(N):
#     if A[i] == MAXS:
#         print(S[-2])
#     else:
#         print(S[-1])


# #
# for i in range(N):
#
#     if i == 0:
#         print(max(A[1:]))
#
#     elif i == N-1:
#         print(max(A[:i]))
#
#     else:
#         low = max(A[0:i])
#         high = max(A[i+1:])
#
#         if high > low:
#             print(high)
#         else:
#             print(low)
