
function main(input) {
  const args = input.split('\n');
  let num = Number(args[0])
  let arr = args[1].split(' ').map(n => Number(n))

  answer = bubbleSort(num, arr)
  console.log(answer[0].join(' '))
  console.log(answer[1])

}

function bubbleSort(length, arr) {
  let flag = true
  let times = 0

  while (flag) {
    flag = false
    for (let i = (length-1); i > 0; i--) {
      if ( arr[i] < arr[i-1] ) {
        let tmp = arr[i-1] 
        arr[i-1] = arr[i]
        arr[i] = tmp
        flag = true
        times++
      }
    }
  }
  return [arr, times]
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

