import java.util.Scanner

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val r = mutable.ArrayBuffer.fill(n)(sc.nextInt())

    var j = 0
    var count = 0

    while (j < n) {
      for (i <- n - 1 to 1 by -1) {
        val x = r(i)
        val y = r(i - 1)
        if (x < y) {
          r(i - 1) = x
          r(i) = y
          count += 1
        }
      }
      j += 1
    }
    println(r.mkString(" "))
    println(count)

  }

}

