let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun i -> Scanf.scanf " %d" @@ fun a -> a, i
let _ = Array.sort (fun x y -> compare y x) a_s;
  Array.iteri (fun i _ -> Printf.printf "%d\n" @@ fst @@ if snd a_s.(0) = i then a_s.(1) else a_s.(0)) a_s