let readInt () = Scanf.scanf " %d" (fun x -> x)

let main () =
  let n = readInt () in
  let a = Array.init n (fun _ -> readInt ()) in
  let b = Array.copy a in
  Array.fast_sort compare b;
  for i=0 to n-1 do
    Printf.printf "%d\n" (if a.(i) = b.(n-1) then b.(n-2) else b.(n-1))
  done

let () = main ()
