n = int(input())
A = [int(input()) for i in range(n)]
X = list(set(A))
X.sort()
X.reverse()
if len(X) == 1 or A.count(max(A)) >= 2:
  for i in range(n):
    print(max(A))
else:
  for i in range(n):
    if A[i] == X[0]:
      print(X[1])
    else:
      print(X[0])