def cc134
    n = gets.chomp.to_i#.map{|x| x.to_i}

    an_t = Struct.new("Arr", :index, :value)
    an = []
    for i in 1..n
        an.push(an_t.new(i, gets.chomp.to_i))
    end
    an = an.sort{|a, b| a.value <=> b.value}

    for i in 1..n
        m = an[-1]
        if m.index == i
            m = an[-2]
        end
        puts m.value
    end
end

cc134