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

    private static void bubbleSort(int[] a, int n) {
        int exchange = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                }
            }
        }
        print(a, n, exchange);
    }

    private static void print(int[] a, int n, int exchange) {
        String[] aStr = new String[n];
        for (int i = 0; i < n; i++) {
            aStr[i] = String.valueOf(a[i]);
        }
        System.out.println(String.join(" ", aStr));
        System.out.println(exchange);
    }
} 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 < n; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
        sc.close();
    }

    private static void bubbleSort(int[] a, int n) {
        int exchange = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                }
            }
        }
        print(a, n, exchange);
    }

    private static void print(int[] a, int n, int exchange) {
        String[] aStr = new String[n];
        for (int i = 0; i < n; i++) {
            aStr[i] = String.valueOf(a[i]);
        }
        System.out.println(String.join(" ", aStr));
        System.out.println(exchange);
    }
} 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 < n; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
        sc.close();
    } 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();
        }
        bubbleSort(a, n);
        sc.close();
    } 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] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc bubbleSort(a, n) bubbleSort a n sc.close() sc.close sc String[] args args private static void bubbleSort(int[] a, int n) {
        int exchange = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                }
            }
        }
        print(a, n, exchange);
    } bubbleSort {
        int exchange = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                }
            }
        }
        print(a, n, exchange);
    } int exchange = 0; exchange 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 ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                }
            }
        } flag {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                }
            }
        } flag = false flag false for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    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 ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                }
            } {
                if (a[i] < a[i - 1]) {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                }
            } if (a[i] < a[i - 1]) {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                } a[i] < a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                } int ai = a[i]; ai a[i] a i a[i] = a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 a[i - 1] = ai a[i - 1] a i - 1 i 1 ai exchange++ exchange flag = true flag true print(a, n, exchange) print a n exchange int[] a a int n n private static void print(int[] a, int n, int exchange) {
        String[] aStr = new String[n];
        for (int i = 0; i < n; i++) {
            aStr[i] = String.valueOf(a[i]);
        }
        System.out.println(String.join(" ", aStr));
        System.out.println(exchange);
    } print {
        String[] aStr = new String[n];
        for (int i = 0; i < n; i++) {
            aStr[i] = String.valueOf(a[i]);
        }
        System.out.println(String.join(" ", aStr));
        System.out.println(exchange);
    } String[] aStr = new String[n]; aStr new String[n] n for (int i = 0; i < n; i++) {
            aStr[i] = String.valueOf(a[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            aStr[i] = String.valueOf(a[i]);
        } {
            aStr[i] = String.valueOf(a[i]);
        } aStr[i] = String.valueOf(a[i]) aStr[i] aStr i String.valueOf(a[i]) String.valueOf String a[i] a i System.out.println(String.join(" ", aStr)) System.out.println System.out System System.out String.join(" ", aStr) String.join String " " aStr System.out.println(exchange) System.out.println System.out System System.out exchange int[] a a int n n int exchange exchange 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 < n; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
        sc.close();
    }

    private static void bubbleSort(int[] a, int n) {
        int exchange = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                }
            }
        }
        print(a, n, exchange);
    }

    private static void print(int[] a, int n, int exchange) {
        String[] aStr = new String[n];
        for (int i = 0; i < n; i++) {
            aStr[i] = String.valueOf(a[i]);
        }
        System.out.println(String.join(" ", aStr));
        System.out.println(exchange);
    }
} 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 < n; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
        sc.close();
    }

    private static void bubbleSort(int[] a, int n) {
        int exchange = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                }
            }
        }
        print(a, n, exchange);
    }

    private static void print(int[] a, int n, int exchange) {
        String[] aStr = new String[n];
        for (int i = 0; i < n; i++) {
            aStr[i] = String.valueOf(a[i]);
        }
        System.out.println(String.join(" ", aStr));
        System.out.println(exchange);
    }
} 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 < n; i++) {
            a[i] = sc.nextInt();
        }
        bubbleSort(a, n);
        sc.close();
    }

    private static void bubbleSort(int[] a, int n) {
        int exchange = 0;
        boolean flag = true;
        while (flag) {
            flag = false;
            for (int i = n - 1; i > 0; i--) {
                if (a[i] < a[i - 1]) {
                    int ai = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = ai;
                    exchange++;
                    flag = true;
                }
            }
        }
        print(a, n, exchange);
    }

    private static void print(int[] a, int n, int exchange) {
        String[] aStr = new String[n];
        for (int i = 0; i < n; i++) {
            aStr[i] = String.valueOf(a[i]);
        }
        System.out.println(String.join(" ", aStr));
        System.out.println(exchange);
    }
}
