import numpy as np

N = int(input())

A = np.array([])

for i in range(N):
	a = int(input())
	A = np.append(A,a)

ans = np.max(A)
j = np.argmax(A)
ans2 = np.max(np.delete(A,j))

for i in range(N):
	if i == j:
		print(int(ans2))
	else:
		print(int(ans))
