import java.util.Scanner;
public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();


        int[] test;
        test = new int[N];

        int tmp;
        int cnt = 0;

        for (int i = 0; i < N; i++) {
            test[i] = sc.nextInt();
        }

        for (int s = N-1; s>0; s--) {
            for (int j = N-1; j >0; j--) {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            }
        }
        for (int j = 0; j < N; j++) {
            System.out.print(test[j]);
            if(j<N-1){
                System.out.print(" ");
            }
            if(j==N-1){
                System.out.println("");
            }
        }
        System.out.println(cnt);

    }
} import java.util.Scanner; Scanner java.util public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();


        int[] test;
        test = new int[N];

        int tmp;
        int cnt = 0;

        for (int i = 0; i < N; i++) {
            test[i] = sc.nextInt();
        }

        for (int s = N-1; s>0; s--) {
            for (int j = N-1; j >0; j--) {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            }
        }
        for (int j = 0; j < N; j++) {
            System.out.print(test[j]);
            if(j<N-1){
                System.out.print(" ");
            }
            if(j==N-1){
                System.out.println("");
            }
        }
        System.out.println(cnt);

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();


        int[] test;
        test = new int[N];

        int tmp;
        int cnt = 0;

        for (int i = 0; i < N; i++) {
            test[i] = sc.nextInt();
        }

        for (int s = N-1; s>0; s--) {
            for (int j = N-1; j >0; j--) {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            }
        }
        for (int j = 0; j < N; j++) {
            System.out.print(test[j]);
            if(j<N-1){
                System.out.print(" ");
            }
            if(j==N-1){
                System.out.println("");
            }
        }
        System.out.println(cnt);

    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();


        int[] test;
        test = new int[N];

        int tmp;
        int cnt = 0;

        for (int i = 0; i < N; i++) {
            test[i] = sc.nextInt();
        }

        for (int s = N-1; s>0; s--) {
            for (int j = N-1; j >0; j--) {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            }
        }
        for (int j = 0; j < N; j++) {
            System.out.print(test[j]);
            if(j<N-1){
                System.out.print(" ");
            }
            if(j==N-1){
                System.out.println("");
            }
        }
        System.out.println(cnt);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] test; test test = new int[N] test new int[N] N int tmp; tmp int cnt = 0; cnt 0 for (int i = 0; i < N; i++) {
            test[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            test[i] = sc.nextInt();
        } {
            test[i] = sc.nextInt();
        } test[i] = sc.nextInt() test[i] test i sc.nextInt() sc.nextInt sc for (int s = N-1; s>0; s--) {
            for (int j = N-1; j >0; j--) {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            }
        } int s = N-1; int s = N-1; s N-1 N 1 s>0 s 0 s-- s-- s {
            for (int j = N-1; j >0; j--) {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            }
        } {
            for (int j = N-1; j >0; j--) {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            }
        } for (int j = N-1; j >0; j--) {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            } int j = N-1; int j = N-1; j N-1 N 1 j >0 j 0 j-- j-- j {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            } {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            } if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                } test[j] < test[j-1] test[j] test j test[j-1] test j-1 j 1 {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                } tmp = test[j] tmp test[j] test j test[j] = test[j-1] test[j] test j test[j-1] test j-1 j 1 test[j-1] = tmp test[j-1] test j-1 j 1 tmp cnt++ cnt for (int j = 0; j < N; j++) {
            System.out.print(test[j]);
            if(j<N-1){
                System.out.print(" ");
            }
            if(j==N-1){
                System.out.println("");
            }
        } int j = 0; int j = 0; j 0 j < N j N j++ j++ j {
            System.out.print(test[j]);
            if(j<N-1){
                System.out.print(" ");
            }
            if(j==N-1){
                System.out.println("");
            }
        } {
            System.out.print(test[j]);
            if(j<N-1){
                System.out.print(" ");
            }
            if(j==N-1){
                System.out.println("");
            }
        } System.out.print(test[j]) System.out.print System.out System System.out test[j] test j if(j<N-1){
                System.out.print(" ");
            } j<N-1 j N-1 N 1 {
                System.out.print(" ");
            } System.out.print(" ") System.out.print System.out System System.out " " if(j==N-1){
                System.out.println("");
            } j==N-1 j N-1 N 1 {
                System.out.println("");
            } System.out.println("") System.out.println System.out System System.out "" System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();


        int[] test;
        test = new int[N];

        int tmp;
        int cnt = 0;

        for (int i = 0; i < N; i++) {
            test[i] = sc.nextInt();
        }

        for (int s = N-1; s>0; s--) {
            for (int j = N-1; j >0; j--) {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            }
        }
        for (int j = 0; j < N; j++) {
            System.out.print(test[j]);
            if(j<N-1){
                System.out.print(" ");
            }
            if(j==N-1){
                System.out.println("");
            }
        }
        System.out.println(cnt);

    }
} public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();


        int[] test;
        test = new int[N];

        int tmp;
        int cnt = 0;

        for (int i = 0; i < N; i++) {
            test[i] = sc.nextInt();
        }

        for (int s = N-1; s>0; s--) {
            for (int j = N-1; j >0; j--) {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            }
        }
        for (int j = 0; j < N; j++) {
            System.out.print(test[j]);
            if(j<N-1){
                System.out.print(" ");
            }
            if(j==N-1){
                System.out.println("");
            }
        }
        System.out.println(cnt);

    }
} Main
import java.util.Scanner;
public class Main{

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();


        int[] test;
        test = new int[N];

        int tmp;
        int cnt = 0;

        for (int i = 0; i < N; i++) {
            test[i] = sc.nextInt();
        }

        for (int s = N-1; s>0; s--) {
            for (int j = N-1; j >0; j--) {
                if (test[j] < test[j-1]) {
                    tmp = test[j];
                    test[j] = test[j-1];
                    test[j-1] = tmp;
                    cnt++;
                }
            }
        }
        for (int j = 0; j < N; j++) {
            System.out.print(test[j]);
            if(j<N-1){
                System.out.print(" ");
            }
            if(j==N-1){
                System.out.println("");
            }
        }
        System.out.println(cnt);

    }
}
