import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)

  def nextInt() = sc.next.toInt

  def swap(x: Int, xs: (List[Int], Int)) = {
    val (lst, cnt) = xs
    lst match {
      case List() => (List(x), cnt)
      case y :: ys =>
        if (x > y) (y :: x :: ys, cnt + 1)
        else (x :: lst, cnt)
    }
  }

  def bubble1(xs: List[Int]): (List[Int], Int) = xs match {
    case List()   => (List(), 0)
    case x :: xs1 => swap(x, bubble1(xs1))
  }

  def bubbleSort(xs: List[Int], cnt: Int): (List[Int], Int) = {
    val (lst, n) = bubble1(xs)
    if (n == 0)
      (lst, cnt)
    else
      bubbleSort(lst, cnt + n)
  }

  val n = nextInt
  val xs = List.fill(n)(nextInt)

  val (lst, cnt) = bubbleSort(xs, 0)
  println(cnt)
  println(lst.mkString(" "))
}

