import numpy as np
N=int(input())
A=[int(input()) for i in range(N)]
Amax=max(A)

Ai=np.argmax(A)
A2max=max(A[:Ai],A[Ai+1:])[0]

for i in range(N):
  if i==Ai:
    print(A2max)
  else:
    print(Amax)