import java.util.Scanner;

public class Main {
    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 < a.length; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
    }

    private static void bubbleSort(int[] a, int n) {
        int sum = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            }
        }
        for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.print(a[n-1]+"\n" + sum+"\n");
    }
}
 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[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
    }

    private static void bubbleSort(int[] a, int n) {
        int sum = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            }
        }
        for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.print(a[n-1]+"\n" + sum+"\n");
    }
} Main 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 < a.length; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
    } 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 < a.length; i++) {
            a[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
            a[i] = sc.nextInt();
        } {
            a[i] = sc.nextInt();
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc bubbleSort(a, n) bubbleSort a n String[] args args private static void bubbleSort(int[] a, int n) {
        int sum = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            }
        }
        for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.print(a[n-1]+"\n" + sum+"\n");
    } bubbleSort {
        int sum = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            }
        }
        for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.print(a[n-1]+"\n" + sum+"\n");
    } int sum = 0; sum 0 boolean flag = true; flag true while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            }
        } flag {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            }
        } flag = false flag false for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            } int i = n - 1; int i = n - 1; i n - 1 n 1 i > 0 i 0 i-- i-- i {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            } {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            } if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                } a[i] < a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                } int emp = a[i]; emp a[i] a i a[i] = a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 a[i - 1] = emp a[i - 1] a i - 1 i 1 emp sum++ sum flag = true flag true for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i] + " ");
        } int i = 0; int i = 0; i 0 i < a.length-1 i a.length-1 a.length a a.length 1 i++ i++ i {
            System.out.print(a[i] + " ");
        } {
            System.out.print(a[i] + " ");
        } System.out.print(a[i] + " ") System.out.print System.out System System.out a[i] + " " a[i] a i " " System.out.print(a[n-1]+"\n" + sum+"\n") System.out.print System.out System System.out a[n-1]+"\n" + sum+"\n" sum a[n-1]+"\n" + sum+"\n" a[n-1] a n-1 n 1 "\n" sum "\n" int[] a a int n n public class Main {
    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 < a.length; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
    }

    private static void bubbleSort(int[] a, int n) {
        int sum = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            }
        }
        for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.print(a[n-1]+"\n" + sum+"\n");
    }
} public class Main {
    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 < a.length; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
    }

    private static void bubbleSort(int[] a, int n) {
        int sum = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            }
        }
        for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.print(a[n-1]+"\n" + sum+"\n");
    }
} 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[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
    }

    private static void bubbleSort(int[] a, int n) {
        int sum = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int emp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = emp;
                    sum++;
                    flag = true;
                }
            }
        }
        for (int i = 0; i < a.length-1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.print(a[n-1]+"\n" + sum+"\n");
    }
}

