#!/usr/bin/env node
// https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/2/ALDS1_2_A

"use strict";
(function (stdin) {
  const [N, a] = stdin.toString().trim().split("\n");
  const A = a.split(" ").map(Number);
  let flag = 1;
  let i = 0;
  let count = 0;
  while (flag) {
    flag = 0;
    for (let j = N - 1; j > i; j--) {
      if (A[j] < A[j - 1]) {
        count++;
        const prev = A[j - 1];
        A[j - 1] = A[j];
        A[j] = prev;
        flag = 1;
      }
    }
    i++;
  }
  console.log(A.join(" "));
  console.log(count);
})(require("fs").readFileSync("/dev/stdin", "UTF-8"));

