import java.util.Scanner;

public class Main {

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

    private static void solve(Scanner in) {
        final int N = in.nextInt();
        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }

        int count = 0;
        for (int i = 0; i < A.length; i++) {
            for (int j = A.length - 1; j > i; j--) {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            }
            // print(A);
            // System.out.println(count);
        }
        print(A);
        System.out.println(count);
    }

    private static void print(int[] A) {
        if (A.length == 0)
            return;
        for (int i = 0; i < A.length - 1; i++)
            System.out.print(A[i] + " ");
        System.out.println(A[A.length - 1]);
    }
} import java.util.Scanner; Scanner java.util public class Main {

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

    private static void solve(Scanner in) {
        final int N = in.nextInt();
        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }

        int count = 0;
        for (int i = 0; i < A.length; i++) {
            for (int j = A.length - 1; j > i; j--) {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            }
            // print(A);
            // System.out.println(count);
        }
        print(A);
        System.out.println(count);
    }

    private static void print(int[] A) {
        if (A.length == 0)
            return;
        for (int i = 0; i < A.length - 1; i++)
            System.out.print(A[i] + " ");
        System.out.println(A[A.length - 1]);
    }
} Main public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    } main {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    } try (Scanner in = new Scanner(System.in)) {
            solve(in);
        } {
            solve(in);
        } Scanner in = new Scanner(System.in) Scanner in = new Scanner(System.in) new Scanner(System.in) solve(in) solve in String[] args args private static void solve(Scanner in) {
        final int N = in.nextInt();
        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }

        int count = 0;
        for (int i = 0; i < A.length; i++) {
            for (int j = A.length - 1; j > i; j--) {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            }
            // print(A);
            // System.out.println(count);
        }
        print(A);
        System.out.println(count);
    } solve {
        final int N = in.nextInt();
        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }

        int count = 0;
        for (int i = 0; i < A.length; i++) {
            for (int j = A.length - 1; j > i; j--) {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            }
            // print(A);
            // System.out.println(count);
        }
        print(A);
        System.out.println(count);
    } final int N = in.nextInt(); N in.nextInt() in.nextInt in final int[] A = new int[N]; A new int[N] N for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            A[i] = in.nextInt();
        } {
            A[i] = in.nextInt();
        } A[i] = in.nextInt() A[i] A i in.nextInt() in.nextInt in int count = 0; count 0 for (int i = 0; i < A.length; i++) {
            for (int j = A.length - 1; j > i; j--) {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            }
            // print(A);
            // System.out.println(count);
        } int i = 0; int i = 0; i 0 i < A.length i A.length A A.length i++ i++ i {
            for (int j = A.length - 1; j > i; j--) {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            }
            // print(A);
            // System.out.println(count);
        } {
            for (int j = A.length - 1; j > i; j--) {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            }
            // print(A);
            // System.out.println(count);
        } for (int j = A.length - 1; j > i; j--) {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            } int j = A.length - 1; int j = A.length - 1; j A.length - 1 A.length A A.length 1 j > i j i j-- j-- j {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            } {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            } if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                } A[j - 1] > A[j] A[j - 1] A j - 1 j 1 A[j] A j {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                } int temp = A[j]; temp A[j] A j A[j] = A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 A[j - 1] = temp A[j - 1] A j - 1 j 1 temp count++ count print(A) print A System.out.println(count) System.out.println System.out System System.out count Scanner in in private static void print(int[] A) {
        if (A.length == 0)
            return;
        for (int i = 0; i < A.length - 1; i++)
            System.out.print(A[i] + " ");
        System.out.println(A[A.length - 1]);
    } print {
        if (A.length == 0)
            return;
        for (int i = 0; i < A.length - 1; i++)
            System.out.print(A[i] + " ");
        System.out.println(A[A.length - 1]);
    } if (A.length == 0)
            return; A.length == 0 A.length A A.length 0 return; 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 System.out System System.out A[i] + " " A[i] A i " " System.out.println(A[A.length - 1]) System.out.println System.out System System.out A[A.length - 1] A A.length - 1 A.length A A.length 1 int[] A A public class Main {

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

    private static void solve(Scanner in) {
        final int N = in.nextInt();
        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }

        int count = 0;
        for (int i = 0; i < A.length; i++) {
            for (int j = A.length - 1; j > i; j--) {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            }
            // print(A);
            // System.out.println(count);
        }
        print(A);
        System.out.println(count);
    }

    private static void print(int[] A) {
        if (A.length == 0)
            return;
        for (int i = 0; i < A.length - 1; i++)
            System.out.print(A[i] + " ");
        System.out.println(A[A.length - 1]);
    }
} public class Main {

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

    private static void solve(Scanner in) {
        final int N = in.nextInt();
        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }

        int count = 0;
        for (int i = 0; i < A.length; i++) {
            for (int j = A.length - 1; j > i; j--) {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            }
            // print(A);
            // System.out.println(count);
        }
        print(A);
        System.out.println(count);
    }

    private static void print(int[] A) {
        if (A.length == 0)
            return;
        for (int i = 0; i < A.length - 1; i++)
            System.out.print(A[i] + " ");
        System.out.println(A[A.length - 1]);
    }
} Main
import java.util.Scanner;

public class Main {

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

    private static void solve(Scanner in) {
        final int N = in.nextInt();
        final int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = in.nextInt();
        }

        int count = 0;
        for (int i = 0; i < A.length; i++) {
            for (int j = A.length - 1; j > i; j--) {
                if (A[j - 1] > A[j]) {
                    int temp = A[j];
                    A[j] = A[j - 1];
                    A[j - 1] = temp;
                    count++;
                }
            }
            // print(A);
            // System.out.println(count);
        }
        print(A);
        System.out.println(count);
    }

    private static void print(int[] A) {
        if (A.length == 0)
            return;
        for (int i = 0; i < A.length - 1; i++)
            System.out.print(A[i] + " ");
        System.out.println(A[A.length - 1]);
    }
}