let read conv = stdin.ReadLine() |> conv
let reads n =
    let acc = System.Collections.Generic.List<int>()
    let mutable max = 0
    let mutable max' = 0
    for i = 1 to n do
        let x = (stdin.ReadLine() |> int)
        if max <= x then max' <- max; max <- x;
        acc.Add(x)
    (acc, max, max')

let n = read int
let (ls, fst, snd) = reads n
for i = 0 to (n-1) do
    printfn "%d" (if ls.[i] = fst then snd else fst)