N= int(input())
num_list = []
max_num = 0
chk = 0
for i in range(N):
	k = int(input())
	if max_num == k :
		chk += 1
	max_num=max(k,max_num)
	num_list.append(k)
if chk != 0:
	for i in range(N):
		print(max_num)
else:
	for i in range(N):
		if num_list[i] != max_num:
			print(max_num)
		else:
			chk_list = num_list[0:i] + num_list[i+1:N]
			chk_list.sort()
			print(chk_list[N-2])
