const input = require('fs').readFileSync('/dev/stdin','utf8')
                           .split("\n")
                           .map(i => Number(i))
const N = input[0]
const A = input.slice(1,input.length-1)
const sort = A.slice(0,A.length).sort((a,b) => a-b)
const max = sort[sort.length-1]
const maxsecond = sort[sort.length-2]

for(var i = 0;i<N;i++) {
    if(max === A[i]) {
        console.log(maxsecond)
    }else{
        console.log(max)
    }
}