N = int(input())
A = []
max1 = 0
max2 = -1
for i in range(N):
  a = int(input())
  A.append(a)
  if max1 <= a:
    max1 = a
  else:
    if max2 <= a:
      max2 = a
if A.count(max1) >= 2:
  for i in range(N):
    print(max1)
else:
  for a in A:
    if a == max1:
      print(max2)
    else:
      print(max1)
