n = int(input())

l = []

for i in range(n):
  l.append(int(input()))

m = max(l)

if l.count(m) >= 2:
  for i in range(n):
    print(m)
  exit()

for i in range(n):
  tmp = l.pop(i)
  
  if tmp != m:
    print(m)
    l.insert(i,tmp)
    continue
  
  print(max(l))
  l.insert(i,tmp)
  