import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val array = IntArray(n){sc.nextInt()}
    var cnt = 0
    (1 until n).forEach { i ->
        (n - 1 downTo i).forEach { j ->
            if (array[j] < array[j - 1]) {
                array.swap(j, j - 1)
                cnt++
            }
        }
    }
    println(array.joinToString(" "))
    println(cnt)
}

fun IntArray.swap(index1: Int, index2: Int) {
    val temp = this[index1]
    this[index1] = this[index2]
    this[index2] = temp
}
