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


sorted_A = list(reversed(sorted(A)))

maxiuam = sorted_A[0]

is_there_tow_maximum = A.count(maxiuam) >= 2
if is_there_tow_maximum:
    answer = (str(maxiuam) + "\n") * N
    print(answer)
    exit()

second = None
for Ai in sorted_A:
    if Ai < maxiuam:
        second = Ai
        break

answer = [second if Ai == maxiuam else maxiuam for Ai in A)]
answer = "\n".join(map(str, answer))

print(answer)
