import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = 0, time = 0, b = 0;
        boolean flag = true;
        size = sc.nextInt();
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = sc.nextInt();
        }
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            }
        }
        for (int k = 0; k < size; k++) {
            System.out.print(a[k]);
            if(k != (size-1))System.out.print(" ");
        }
        System.out.print("\n");
        System.out.println(time);


    }
}
 import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = 0, time = 0, b = 0;
        boolean flag = true;
        size = sc.nextInt();
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = sc.nextInt();
        }
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            }
        }
        for (int k = 0; k < size; k++) {
            System.out.print(a[k]);
            if(k != (size-1))System.out.print(" ");
        }
        System.out.print("\n");
        System.out.println(time);


    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = 0, time = 0, b = 0;
        boolean flag = true;
        size = sc.nextInt();
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = sc.nextInt();
        }
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            }
        }
        for (int k = 0; k < size; k++) {
            System.out.print(a[k]);
            if(k != (size-1))System.out.print(" ");
        }
        System.out.print("\n");
        System.out.println(time);


    } main {
        Scanner sc = new Scanner(System.in);
        int size = 0, time = 0, b = 0;
        boolean flag = true;
        size = sc.nextInt();
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = sc.nextInt();
        }
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            }
        }
        for (int k = 0; k < size; k++) {
            System.out.print(a[k]);
            if(k != (size-1))System.out.print(" ");
        }
        System.out.print("\n");
        System.out.println(time);


    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int size = 0 size 0 time = 0 time 0 b = 0; b 0 boolean flag = true; flag true size = sc.nextInt() size sc.nextInt() sc.nextInt sc int[] a = new int[size]; a new int[size] size for (int i = 0; i < size; i++) {
            a[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < size i size i++ i++ i {
            a[i] = sc.nextInt();
        } {
            a[i] = sc.nextInt();
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            }
        } flag {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            }
        } flag = false flag false for (int j = size - 1; j > 0; j--) {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            } int j = size - 1; int j = size - 1; j size - 1 size 1 j > 0 j 0 j-- j-- j {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            } {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            } if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                } a[j] < a[j - 1] a[j] a j a[j - 1] a j - 1 j 1 {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                } b = a[j] b a[j] a j a[j] = a[j - 1] a[j] a j a[j - 1] a j - 1 j 1 a[j - 1] = b a[j - 1] a j - 1 j 1 b time++ time flag = true flag true for (int k = 0; k < size; k++) {
            System.out.print(a[k]);
            if(k != (size-1))System.out.print(" ");
        } int k = 0; int k = 0; k 0 k < size k size k++ k++ k {
            System.out.print(a[k]);
            if(k != (size-1))System.out.print(" ");
        } {
            System.out.print(a[k]);
            if(k != (size-1))System.out.print(" ");
        } System.out.print(a[k]) System.out.print System.out System System.out a[k] a k if(k != (size-1))System.out.print(" "); k != (size-1) k (size-1) size 1 System.out.print(" ") System.out.print System.out System System.out " " System.out.print("\n") System.out.print System.out System System.out "\n" System.out.println(time) System.out.println System.out System System.out time String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = 0, time = 0, b = 0;
        boolean flag = true;
        size = sc.nextInt();
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = sc.nextInt();
        }
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            }
        }
        for (int k = 0; k < size; k++) {
            System.out.print(a[k]);
            if(k != (size-1))System.out.print(" ");
        }
        System.out.print("\n");
        System.out.println(time);


    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = 0, time = 0, b = 0;
        boolean flag = true;
        size = sc.nextInt();
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = sc.nextInt();
        }
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            }
        }
        for (int k = 0; k < size; k++) {
            System.out.print(a[k]);
            if(k != (size-1))System.out.print(" ");
        }
        System.out.print("\n");
        System.out.println(time);


    }
} Main
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int size = 0, time = 0, b = 0;
        boolean flag = true;
        size = sc.nextInt();
        int[] a = new int[size];
        for (int i = 0; i < size; i++) {
            a[i] = sc.nextInt();
        }
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (a[j] < a[j - 1]) {
                    b = a[j];
                    a[j] = a[j - 1];
                    a[j - 1] = b;
                    time++;
                    flag = true;
                }
            }
        }
        for (int k = 0; k < size; k++) {
            System.out.print(a[k]);
            if(k != (size-1))System.out.print(" ");
        }
        System.out.print("\n");
        System.out.println(time);


    }
}

