n = int(input())
a = []
max_value = 0
max_count = 1

for i in range(n):
  value = int(input())
  
  if value == max_value:
    max_count += 1
  
  max_value = max(max_value, value)
  a.append(value)
  
if max_count > 1:
  for i in range(n):
    print(max_value)
else:
  max_index = a.index(max_value)
  second_max = max(a[:max_index] + a[max_index+1:])
  
  for i in range(n):
    if i != max_index:
      print(max_value)
    else:
      print(second_max)