def main():
	import sys
	input = sys.stdin.readline
	N = int(input())
	A = [int(input()) for _ in range(N)]
	maxNum = max(A)
	maxIndex = [i for i, x in enumerate(A) if x == max(A)]
	if len(maxIndex) > 1:
		for _ in range(N):
			print(maxNum)
	elif maxIndex[0] == 0:
		print(max(A[1:]))
		for i in range(1, N):
			print(maxNum)
	elif maxIndex[0] == N-1:
		for i in range(N-1):
			print(maxNum)
		print(max(A[:N-1]))
	else:
		for i in range(maxIndex[0]):
			print(maxNum)
		prev = max(max(A[:maxIndex[0]]), max(A[maxIndex[0]+1:]))
		print(prev)
		for i in range(maxIndex[0]+1, N):
			print(maxNum)

if __name__ == '__main__':
    main()