n = int(input())

a = [int(input()) for i in range(n)]

a_max = max(a)
a_max_count = a.count(a_max)

if a_max_count > 1:
  for i in range(n):
    print(a_max)
    
else:
  for i in range(n):
    if a[i] == a_max:
      print(max(max(a[:i]), max(a[i+1:])))
      
    else:
      print(a_max)
