n = int(input())
a = [int(input()) for _ in range(n)]
l, r = [1] * n, [1] * n
for i in range(1, n):
	l[i] = max(l[i - 1], a[i])
for i in range(n - 2, -1, -1):
	r[i] = max(r[i + 1], a[i])
l[0] = max(l[0], a[0])
r[-1] = max(r[-1], a[-1])
for i in range(n):
	if i == 0:
		print(r[i])
	elif i == n - 1:
		print(l[i])
	else:
		print(max(l[i - 1], r[i + 1]))