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

max_val = max(A)
subset = list(set(A))
subset.remove(max_val)
max_val_2 = max(subset)
count = A.count(max_val)

for i, num in enumerate(A):
  if num < max_val:
    print(max_val)
  else:
    if count > 1:
      print(max_val)
    else:
      print(max_val_2)