import sys, re
input = sys.stdin.readline

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

temp_list = sorted(a)
m = temp_list[-1]
m_dash = m + 1

for i in range(1, n):
  if temp_list[-i] == m:
    continue
  else:
    m_dash = temp_list[-i]

for a_i in a:
  if not a_i == m:
    print(m)
  else:
    print(m_dash)