open Array
let n = read_int ()
let a = init n @@ fun _ -> Scanf.scanf "%d\n" @@ fun d -> d
let b = copy a
let () = fast_sort (fun x y -> if x = y then 0 else if x < y then 1 else -1) b
let amax, asec = b.(0), b.(1)
let () = iter (fun x -> print_int x; print_newline ()) (map (fun x -> if x = amax then asec else amax) a)