# -*- coding: utf-8 -*-
N = int(input())
A = [int(input()) for _ in range(N)]
setA = set(A)
tempA = list(setA)
R = sorted(tempA, reverse=True)
max_v = R[0]
max_v2 = R[1]

for i in range(N):
  if A[i] == max_v:
    print(max_v2)
  else:
    print(max_v)
