N = int(input())

A = []
for i in range(N):
  tmp = int(input())
  A.append(tmp)

A_set = set(A)
if len(A_set)==1:
  second_max = A[0]
else:
  second_max = sorted(A_set)[-2]
tmp_max = max(set(A))
tmp_max_list = [i for i, x in enumerate(A) if x == tmp_max]


for i in range(N):
  if i in tmp_max_list:
    print(second_max)
  else:
    print(tmp_max)
