let c = ref 0

let bubblesort a =
  for i = 0 to Array.length a - 1 do
    for j = Array.length a - 1 downto i+1 do
      if a.(j) < a.(j-1) then
        ( let b = a.(j) in
          a.(j) <- a.(j-1);
          a.(j-1) <- b;
          c := !c + 1;
        )
      else ()
    done
  done

let () =
  let _ = Scanf.scanf "%d\n" (fun x -> x) in
  let l = read_line ()
            |> Str.split (Str.regexp " ")
            |> List.map int_of_string
            |> Array.of_list in
  bubblesort l;
  Array.to_list l
    |> List.map string_of_int
    |> String.concat " "
    |> Printf.printf "%s\n";
  Printf.printf "%d\n" !c