function Main(input)
{
    const args = input.split('\n');
    const numbers = args.slice(1, args.length).map(x => parseInt(x, 10));
    const sorted_numbers = numbers.slice().sort((a, b) => a - b);
    const last_number = sorted_numbers[sorted_numbers.length - 1];
    const next_number = sorted_numbers[sorted_numbers.length - 2];

    for(var v of numbers) {
        console.log(last_number === v ? next_number : last_number);
    }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
