n=int(input())
a=[]
max_i=0
max_n=0
for i in range(n):
  a.append(int(input()))
  max_i=a.index(max(a))

max_n=max(a)
a.pop(max_i)
semi_n=max(a)

for j in range(n):
  if j != max_i:
    print(max_n)
  else:
    print(semi_n)
