N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
m = max(A)
for i in range(N):
  if A.count(m) >= 2:
    print(m)
  elif m == A[i]:
    B = A.pop(i)
    print(max(A))
    A.insert(i,B)
  else:
    print(m)