import java.util.Scanner;

/**
 * Created by zhangrunfeng on 2019-04-30
 */
public class Main {

    private int arrayLen;
    private int arr[];

    private void init(Scanner sc) {
        arrayLen = sc.nextInt();
        arr = new int[arrayLen];
        for (int idx = 0; idx < arrayLen; idx++) {
            arr[idx] = sc.nextInt();
        }
    }

    private void printArray() {
        for (int idx = 0; idx < arrayLen-1; idx++) {
            System.out.print(arr[idx] + " ");
        }
        System.out.println(arr[arrayLen-1]);
    }

    private int bubbleSort() {
        int count = 0;

        boolean flag = true;
        for (int iter = 0; iter < arrayLen-1; iter+=1) {
            if (!flag) break;
            flag = false;

            for (int idx = 0; idx < arrayLen-1-iter; idx+=1) {
                if (arr[idx] > arr[idx+1]) {
                    count += 1;

                    // swap arr[idx] and arr[idx+1]
                    int tmp = arr[idx];
                    arr[idx] = arr[idx+1];
                    arr[idx+1] = tmp;
                    flag = true;
                }
            }

        }

        printArray();

        return count;
    }

    public static void main(String[] args) {
        Main bubbleSort = new Main();
        Scanner sc = new Scanner(System.in);
        bubbleSort.init(sc);
        int res = bubbleSort.bubbleSort();
        System.out.println(res);
    }
}


/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz