import itertools
from sys import stdin
input = stdin.readline

N = int(input())
A = [int(input()) for _ in range(N)]

max_value, max_cnt, sub_max = -1, 0, -1
for v in A:
	if v > max_value:
		sub_max = max_value
		max_value = v
		max_cnt = 1
	elif v == max_value:
		max_cnt += 1
	elif v > sub_max:
		sub_max = v

if max_cnt == 2:
	print('\n'.join([str(max_value)] * N))
else:
	for v in A:
		print('%d' % (max_value if v != max_value else sub_max))
