N = int(input())
A = [int(input()) for _ in range(N)]
m = max(A)
ans = [m for _ in range(N)]
if A.count(M) > 1:
    print('\n'.join(ans))
    exit()
AA = A[:]
AA.remove(M)
mm = max(AA)
for n in range(N):
    if A[n] == m:
        ans[n] = mm
        break
print('\n'.join(ans))