n = int(input())
v = []
f = []
for i in range(n):
	x = int(input())
	v.append(x)
	f.append(x)
f.sort()
print(v)
for i in range(n):
	if v[i] == f[n-1]:
		print(str(f[n-2]) + ' ', end='')
	else:
		print(str(f[n-1]) + ' ', end='')	