import java.util.Scanner;
import java.lang.StringBuilder;

class Main {


    private static String toString(int[] numbers){
        StringBuilder ans = new StringBuilder().append(numbers[0]);
        for (int x = 1; x < numbers.length; x++)
            ans.append(" ").append(numbers[x]);
        return ans.toString();
    }

    public static void main(String[] args) {



        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] A = new int[n];

        for (int i = 0; i < n; i++)
            A[i] = sc.nextInt();


        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = n-1; j > i; j--) {
                if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                }

            }
        }

        System.out.println(toString(A));
        System.out.println(count);
    }
}
 import java.util.Scanner; Scanner java.util import java.lang.StringBuilder; StringBuilder java.lang class Main {


    private static String toString(int[] numbers){
        StringBuilder ans = new StringBuilder().append(numbers[0]);
        for (int x = 1; x < numbers.length; x++)
            ans.append(" ").append(numbers[x]);
        return ans.toString();
    }

    public static void main(String[] args) {



        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] A = new int[n];

        for (int i = 0; i < n; i++)
            A[i] = sc.nextInt();


        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = n-1; j > i; j--) {
                if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                }

            }
        }

        System.out.println(toString(A));
        System.out.println(count);
    }
} Main private static String toString(int[] numbers){
        StringBuilder ans = new StringBuilder().append(numbers[0]);
        for (int x = 1; x < numbers.length; x++)
            ans.append(" ").append(numbers[x]);
        return ans.toString();
    } toString {
        StringBuilder ans = new StringBuilder().append(numbers[0]);
        for (int x = 1; x < numbers.length; x++)
            ans.append(" ").append(numbers[x]);
        return ans.toString();
    } StringBuilder ans = new StringBuilder().append(numbers[0]); ans new StringBuilder().append(numbers[0]) new StringBuilder().append new StringBuilder() numbers[0] numbers 0 for (int x = 1; x < numbers.length; x++)
            ans.append(" ").append(numbers[x]); int x = 1; int x = 1; x 1 x < numbers.length x numbers.length numbers numbers.length x++ x++ x ans.append(" ").append(numbers[x]); ans.append(" ").append(numbers[x]) ans.append(" ").append ans.append(" ") ans.append ans " " numbers[x] numbers x return ans.toString(); ans.toString() ans.toString ans int[] numbers numbers public static void main(String[] args) {



        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] A = new int[n];

        for (int i = 0; i < n; i++)
            A[i] = sc.nextInt();


        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = n-1; j > i; j--) {
                if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                }

            }
        }

        System.out.println(toString(A));
        System.out.println(count);
    } main {



        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] A = new int[n];

        for (int i = 0; i < n; i++)
            A[i] = sc.nextInt();


        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = n-1; j > i; j--) {
                if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                }

            }
        }

        System.out.println(toString(A));
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] A = new int[n]; A new int[n] n for (int i = 0; i < n; i++)
            A[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i A[i] = sc.nextInt(); A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int count = 0; count 0 for (int i = 0; i < n; i++) {
            for (int j = n-1; j > i; j--) {
                if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                }

            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for (int j = n-1; j > i; j--) {
                if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                }

            }
        } {
            for (int j = n-1; j > i; j--) {
                if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                }

            }
        } for (int j = n-1; j > i; j--) {
                if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                }

            } int j = n-1; int j = n-1; j n-1 n 1 j > i j i j-- j-- j {
                if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                }

            } {
                if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                }

            } if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                } A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 {
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                } int temp = A[j-1]; temp A[j-1] A j-1 j 1 A[j-1] = A[j] A[j-1] A j-1 j 1 A[j] A j A[j] = temp A[j] A j temp count++ count System.out.println(toString(A)) System.out.println System.out System System.out toString(A) toString A System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.Scanner;
import java.lang.StringBuilder;

class Main {


    private static String toString(int[] numbers){
        StringBuilder ans = new StringBuilder().append(numbers[0]);
        for (int x = 1; x < numbers.length; x++)
            ans.append(" ").append(numbers[x]);
        return ans.toString();
    }

    public static void main(String[] args) {



        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int[] A = new int[n];

        for (int i = 0; i < n; i++)
            A[i] = sc.nextInt();


        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = n-1; j > i; j--) {
                if(A[j] < A[j-1]){
                    int temp = A[j-1];
                    A[j-1] = A[j];
                    A[j] = temp;
                    count++;
                }

            }
        }

        System.out.println(toString(A));
        System.out.println(count);
    }
}

