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();

        int swapCount = 0;
        boolean sorted = false;
        while (!sorted) {
            sorted = true;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            }
        }
        printlnArray(a);
        System.out.println(swapCount);
    }
    
    static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
    
    private static void printlnArray(int[] a) {
        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) {
        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();

        int swapCount = 0;
        boolean sorted = false;
        while (!sorted) {
            sorted = true;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            }
        }
        printlnArray(a);
        System.out.println(swapCount);
    }
    
    static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
    
    private static void printlnArray(int[] a) {
        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) {
        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();

        int swapCount = 0;
        boolean sorted = false;
        while (!sorted) {
            sorted = true;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            }
        }
        printlnArray(a);
        System.out.println(swapCount);
    } 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();

        int swapCount = 0;
        boolean sorted = false;
        while (!sorted) {
            sorted = true;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            }
        }
        printlnArray(a);
        System.out.println(swapCount);
    } 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] a i sc.nextInt() sc.nextInt sc int swapCount = 0; swapCount 0 boolean sorted = false; sorted false while (!sorted) {
            sorted = true;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            }
        } !sorted sorted {
            sorted = true;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            }
        } sorted = true sorted true for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            } int i = n - 1; int i = n - 1; i n - 1 n 1 i >= 1 i 1 i-- i-- i {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            } {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            } if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                } a[i] < a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                } swap(a, i-1, i) swap a i-1 i 1 i swapCount++ swapCount sorted = false sorted false printlnArray(a) printlnArray a System.out.println(swapCount) System.out.println System.out System System.out swapCount String[] args args static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    } swap {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    } int temp = a[i]; temp a[i] a i a[i] = a[j] a[i] a i a[j] a j a[j] = temp a[j] a j temp int[] a a int i i int j j private static void printlnArray(int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println(a[a.length - 1]);
    } printlnArray {
        for (int i = 0; i < a.length - 1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println(a[a.length - 1]);
    } 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.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) {
        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();

        int swapCount = 0;
        boolean sorted = false;
        while (!sorted) {
            sorted = true;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            }
        }
        printlnArray(a);
        System.out.println(swapCount);
    }
    
    static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
    
    private static void printlnArray(int[] a) {
        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) {
        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();

        int swapCount = 0;
        boolean sorted = false;
        while (!sorted) {
            sorted = true;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            }
        }
        printlnArray(a);
        System.out.println(swapCount);
    }
    
    static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
    
    private static void printlnArray(int[] a) {
        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) {
        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();

        int swapCount = 0;
        boolean sorted = false;
        while (!sorted) {
            sorted = true;
            for (int i = n - 1; i >= 1; i--) {
                if (a[i] < a[i - 1]) {
                    swap(a, i-1, i);
                    swapCount++;
                    sorted = false;
                }
            }
        }
        printlnArray(a);
        System.out.println(swapCount);
    }
    
    static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }
    
    private static void printlnArray(int[] a) {
        for (int i = 0; i < a.length - 1; i++) {
            System.out.print(a[i] + " ");
        }
        System.out.println(a[a.length - 1]);
    }
}
