function Main(input) {
	input = input.split("\n");
	const N = parseInt(input[0])
	const As = input.slice(1).map(x => parseInt(x))
	var max = As[0] > As[1] ? 1 : 0
	var second = As[0] > As[1] ? 0 : 1
	As.forEach((e,i) => {
		if(As[max] < e){
			second = max
			max = i
		}else if(As[second] < e){
			second = i
		}
	})
	for(i=0; i < N; i++){
		if(i == max){
			console.log(As[second])
		}else{
			console.log(As[max])
		}
	}
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));