N = int(input())
A = []
for i in range(N):
  A.append(int(input()))
B = list(A)
B.sort()
m1 = B[N-1]
m2 = B[N-2]
for i in range(N):
  if A.count(m1) >= 2:
    print(m1)
  else:
    if A[i] == m1:
      print(m2)
    else:
      print(m1)