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)
	else:
		for i in range(N):
			if i != maxIndex[0]:
				print(maxNum)
			else:
				prev = max(max(A[:i]), max(A[i+1:]))
				print(prev)

if __name__ == '__main__':
    main()