N=int(input())
A=[]
for n in range(N):
	A+=[int(input())]
B=A.copy()
B.sort()
if N==2:
	C=int(B[-1])
	D=int(B[-2])
	for i in A:
		if i==D:
			print(C)
		else:
			print(D)

else:
	print(A[1])
	print(A[0])