N = int(input())
values = []

for i in range(N):
  values.append(int(input()))
  
a = max(values)

copy_values = [v for v in values]

while(a in copy_values):
  copy_values.remove(a)

if len(copy_values) == 0:
  b = a
else:
  b = max(copy_values)

for i in range(N):
  if values[i] == a:
    print(b)
  else:
    print(a)
