N = input()
A = [0]*N
for i in range(N):
  A[i] = input()

m = max(A)
c = A.count(m)
if c==2:
  for _ in range(N):
    print m
else:
  for a in A:
    if a==m:
      print max(t for t in A if t!=m)
    else:
      print m
