function Main(input) {
    input = input.split("\n").map(Number);
    var flag = false;
    var max = 0;
    input.shift();
    input.forEach(function(val){
        if(max<val){
            max = val;
            flag = false;
        }else if(max == val){
            flag = true;
        }
    })
    var next = 0;
        input.forEach(function(val){
            if(next<val&&val!=max) next = val;
    })
    input.forEach(function(val){
        console.log((flag||(val!=max))?max:next);
    })
}Main(require("fs").readFileSync("/dev/stdin","utf8").trim());
