N = int(input())
A = [None for _ in range(N)]
for i in range(N):
  A[i] = int(input())
MAX = max(A)
As = sorted(list(set(A)),reverse = True)
if len(set(A)) > 1:
  second = As[1]
for i in range(N):
  if A[i] != MAX:
    print(MAX)
  elif len(set(A)) == 1:
    print(MAX)
  else:
    print(second)