N = int(input())
A = [int(input()) for i in range(N)]

max_value = max(A)
max_index = [i for i, x in enumerate(A) if x == max_value]
second = sorted(A)[-2]

for i in range(N):
  if i in max_index:
    if len(max_index) >= 2:
      print(max_value)
    else:
      print(second)
  else:
    print(max_value)

