import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] element = br.readLine().split(" ");
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(element[i]);
        }
        
        int count = bubbleSort(a);

        StringBuilder output = new StringBuilder("");
        for (int i = 0; i < n; i++) {
            output.append(a[i]);
            if (i != n-1) {
                output.append(" ");
            }
        }
        System.out.println(output.toString());
        System.out.println(count);
    }

    public static int bubbleSort (int[] a) {
        int i, j, temp;
        int n = a.length - 1;
        int count = 0;
        for (i = 0; i < n; i++) {
            for (j = n; j > i; j--) {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            }
        }
        return count;
    }
} import java.io.*; io.* java class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] element = br.readLine().split(" ");
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(element[i]);
        }
        
        int count = bubbleSort(a);

        StringBuilder output = new StringBuilder("");
        for (int i = 0; i < n; i++) {
            output.append(a[i]);
            if (i != n-1) {
                output.append(" ");
            }
        }
        System.out.println(output.toString());
        System.out.println(count);
    }

    public static int bubbleSort (int[] a) {
        int i, j, temp;
        int n = a.length - 1;
        int count = 0;
        for (i = 0; i < n; i++) {
            for (j = n; j > i; j--) {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            }
        }
        return count;
    }
} Main public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] element = br.readLine().split(" ");
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(element[i]);
        }
        
        int count = bubbleSort(a);

        StringBuilder output = new StringBuilder("");
        for (int i = 0; i < n; i++) {
            output.append(a[i]);
            if (i != n-1) {
                output.append(" ");
            }
        }
        System.out.println(output.toString());
        System.out.println(count);
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] element = br.readLine().split(" ");
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(element[i]);
        }
        
        int count = bubbleSort(a);

        StringBuilder output = new StringBuilder("");
        for (int i = 0; i < n; i++) {
            output.append(a[i]);
            if (i != n-1) {
                output.append(" ");
            }
        }
        System.out.println(output.toString());
        System.out.println(count);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br String[] element = br.readLine().split(" "); element br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(element[i]);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = Integer.parseInt(element[i]);
        } {
            a[i] = Integer.parseInt(element[i]);
        } a[i] = Integer.parseInt(element[i]) a[i] a i Integer.parseInt(element[i]) Integer.parseInt Integer element[i] element i int count = bubbleSort(a); count bubbleSort(a) bubbleSort a StringBuilder output = new StringBuilder(""); output new StringBuilder("") for (int i = 0; i < n; i++) {
            output.append(a[i]);
            if (i != n-1) {
                output.append(" ");
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            output.append(a[i]);
            if (i != n-1) {
                output.append(" ");
            }
        } {
            output.append(a[i]);
            if (i != n-1) {
                output.append(" ");
            }
        } output.append(a[i]) output.append output a[i] a i if (i != n-1) {
                output.append(" ");
            } i != n-1 i n-1 n 1 {
                output.append(" ");
            } output.append(" ") output.append output " " System.out.println(output.toString()) System.out.println System.out System System.out output.toString() output.toString output System.out.println(count) System.out.println System.out System System.out count String[] args args public static int bubbleSort (int[] a) {
        int i, j, temp;
        int n = a.length - 1;
        int count = 0;
        for (i = 0; i < n; i++) {
            for (j = n; j > i; j--) {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            }
        }
        return count;
    } bubbleSort {
        int i, j, temp;
        int n = a.length - 1;
        int count = 0;
        for (i = 0; i < n; i++) {
            for (j = n; j > i; j--) {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            }
        }
        return count;
    } int i i j j temp; temp int n = a.length - 1; n a.length - 1 a.length a a.length 1 int count = 0; count 0 for (i = 0; i < n; i++) {
            for (j = n; j > i; j--) {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            }
        } i = 0; i = 0 i 0 i < n i n i++ i++ i {
            for (j = n; j > i; j--) {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            }
        } {
            for (j = n; j > i; j--) {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            }
        } for (j = n; j > i; j--) {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            } j = n; j = n j n j > i j i j-- j-- j {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            } {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            } if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                } a[j-1] > a[j] a[j-1] a j-1 j 1 a[j] a j {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                } 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 return count; count int[] a a
import java.io.*;

class Main {
    public static void main (String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        String[] element = br.readLine().split(" ");
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = Integer.parseInt(element[i]);
        }
        
        int count = bubbleSort(a);

        StringBuilder output = new StringBuilder("");
        for (int i = 0; i < n; i++) {
            output.append(a[i]);
            if (i != n-1) {
                output.append(" ");
            }
        }
        System.out.println(output.toString());
        System.out.println(count);
    }

    public static int bubbleSort (int[] a) {
        int i, j, temp;
        int n = a.length - 1;
        int count = 0;
        for (i = 0; i < n; i++) {
            for (j = n; j > i; j--) {
                if (a[j-1] > a[j]) {
                    temp = a[j-1];
                    a[j-1] = a[j];
                    a[j] = temp;
                    count++;
                }
            }
        }
        return count;
    }
}