N = int(input())
S = []
for _ in range(N):
    S.append(input())  # S += [input()] とも書ける

B=S.copy()
B.sort()
if N!=2:
	C=int(B[N-1])
	D=int(B[N-2])
	for i in S:
		if int(i)>=C:
			print(D)
		else:
			print(C)

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