import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        int[] inputs = input();
//        int[] inputs = mockup();
        int swapCount = 0;

        for (int i = 0; i < inputs.length; i++) {
            for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            }
        }
        StringBuilder output = new StringBuilder();
        for (int i : inputs) {
            output.append(i + " ");
        }
        String outputString = output.toString();
        System.out.println(outputString.substring(0,outputString.length() - 1));
        System.out.println(swapCount);
    }

    private static int[] mockup() {
        int a[] = {1,2,3,4,5};
        return a;
    }

    private static void swap(int[] inputs, int j, int i) {
        int a = inputs[j];
        int b = inputs[i];
        inputs[i] = a;
        inputs[j] = b;
    }


    public static int[] input() {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        int[] inputs = new int[count];
        for (int i = 0; i < count; i++) {
            inputs[i] = in.nextInt();
        }
        in.close();
        return inputs;
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String args[]) {

        int[] inputs = input();
//        int[] inputs = mockup();
        int swapCount = 0;

        for (int i = 0; i < inputs.length; i++) {
            for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            }
        }
        StringBuilder output = new StringBuilder();
        for (int i : inputs) {
            output.append(i + " ");
        }
        String outputString = output.toString();
        System.out.println(outputString.substring(0,outputString.length() - 1));
        System.out.println(swapCount);
    }

    private static int[] mockup() {
        int a[] = {1,2,3,4,5};
        return a;
    }

    private static void swap(int[] inputs, int j, int i) {
        int a = inputs[j];
        int b = inputs[i];
        inputs[i] = a;
        inputs[j] = b;
    }


    public static int[] input() {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        int[] inputs = new int[count];
        for (int i = 0; i < count; i++) {
            inputs[i] = in.nextInt();
        }
        in.close();
        return inputs;
    }

} Main public static void main(String args[]) {

        int[] inputs = input();
//        int[] inputs = mockup();
        int swapCount = 0;

        for (int i = 0; i < inputs.length; i++) {
            for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            }
        }
        StringBuilder output = new StringBuilder();
        for (int i : inputs) {
            output.append(i + " ");
        }
        String outputString = output.toString();
        System.out.println(outputString.substring(0,outputString.length() - 1));
        System.out.println(swapCount);
    } main {

        int[] inputs = input();
//        int[] inputs = mockup();
        int swapCount = 0;

        for (int i = 0; i < inputs.length; i++) {
            for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            }
        }
        StringBuilder output = new StringBuilder();
        for (int i : inputs) {
            output.append(i + " ");
        }
        String outputString = output.toString();
        System.out.println(outputString.substring(0,outputString.length() - 1));
        System.out.println(swapCount);
    } int[] inputs = input(); inputs input() input int swapCount = 0; swapCount 0 for (int i = 0; i < inputs.length; i++) {
            for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            }
        } int i = 0; int i = 0; i 0 i < inputs.length i inputs.length inputs inputs.length i++ i++ i {
            for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            }
        } {
            for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            }
        } for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            } int j = inputs.length - 1; int j = inputs.length - 1; j inputs.length - 1 inputs.length inputs inputs.length 1 j > i j i j-- j-- j {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            } {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            } if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                } inputs[j] < inputs[j-1] inputs[j] inputs j inputs[j-1] inputs j-1 j 1 {
                    swap(inputs, j, j-1);
                    swapCount++;
                } swap(inputs, j, j-1) swap inputs j j-1 j 1 swapCount++ swapCount StringBuilder output = new StringBuilder(); output new StringBuilder() for (int i : inputs) {
            output.append(i + " ");
        } int i inputs {
            output.append(i + " ");
        } {
            output.append(i + " ");
        } output.append(i + " ") output.append output i + " " i " " String outputString = output.toString(); outputString output.toString() output.toString output System.out.println(outputString.substring(0,outputString.length() - 1)) System.out.println System.out System System.out outputString.substring(0,outputString.length() - 1) outputString.substring outputString 0 outputString.length() - 1 outputString.length() outputString.length outputString 1 System.out.println(swapCount) System.out.println System.out System System.out swapCount String args[] args private static int[] mockup() {
        int a[] = {1,2,3,4,5};
        return a;
    } mockup {
        int a[] = {1,2,3,4,5};
        return a;
    } int a[] = {1,2,3,4,5}; a {1,2,3,4,5} 1 2 3 4 5 return a; a private static void swap(int[] inputs, int j, int i) {
        int a = inputs[j];
        int b = inputs[i];
        inputs[i] = a;
        inputs[j] = b;
    } swap {
        int a = inputs[j];
        int b = inputs[i];
        inputs[i] = a;
        inputs[j] = b;
    } int a = inputs[j]; a inputs[j] inputs j int b = inputs[i]; b inputs[i] inputs i inputs[i] = a inputs[i] inputs i a inputs[j] = b inputs[j] inputs j b int[] inputs inputs int j j int i i public static int[] input() {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        int[] inputs = new int[count];
        for (int i = 0; i < count; i++) {
            inputs[i] = in.nextInt();
        }
        in.close();
        return inputs;
    } input {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        int[] inputs = new int[count];
        for (int i = 0; i < count; i++) {
            inputs[i] = in.nextInt();
        }
        in.close();
        return inputs;
    } Scanner in = new Scanner(System.in); in new Scanner(System.in) int count = in.nextInt(); count in.nextInt() in.nextInt in int[] inputs = new int[count]; inputs new int[count] count for (int i = 0; i < count; i++) {
            inputs[i] = in.nextInt();
        } int i = 0; int i = 0; i 0 i < count i count i++ i++ i {
            inputs[i] = in.nextInt();
        } {
            inputs[i] = in.nextInt();
        } inputs[i] = in.nextInt() inputs[i] inputs i in.nextInt() in.nextInt in in.close() in.close in return inputs; inputs public class Main {

    public static void main(String args[]) {

        int[] inputs = input();
//        int[] inputs = mockup();
        int swapCount = 0;

        for (int i = 0; i < inputs.length; i++) {
            for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            }
        }
        StringBuilder output = new StringBuilder();
        for (int i : inputs) {
            output.append(i + " ");
        }
        String outputString = output.toString();
        System.out.println(outputString.substring(0,outputString.length() - 1));
        System.out.println(swapCount);
    }

    private static int[] mockup() {
        int a[] = {1,2,3,4,5};
        return a;
    }

    private static void swap(int[] inputs, int j, int i) {
        int a = inputs[j];
        int b = inputs[i];
        inputs[i] = a;
        inputs[j] = b;
    }


    public static int[] input() {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        int[] inputs = new int[count];
        for (int i = 0; i < count; i++) {
            inputs[i] = in.nextInt();
        }
        in.close();
        return inputs;
    }

} public class Main {

    public static void main(String args[]) {

        int[] inputs = input();
//        int[] inputs = mockup();
        int swapCount = 0;

        for (int i = 0; i < inputs.length; i++) {
            for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            }
        }
        StringBuilder output = new StringBuilder();
        for (int i : inputs) {
            output.append(i + " ");
        }
        String outputString = output.toString();
        System.out.println(outputString.substring(0,outputString.length() - 1));
        System.out.println(swapCount);
    }

    private static int[] mockup() {
        int a[] = {1,2,3,4,5};
        return a;
    }

    private static void swap(int[] inputs, int j, int i) {
        int a = inputs[j];
        int b = inputs[i];
        inputs[i] = a;
        inputs[j] = b;
    }


    public static int[] input() {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        int[] inputs = new int[count];
        for (int i = 0; i < count; i++) {
            inputs[i] = in.nextInt();
        }
        in.close();
        return inputs;
    }

} Main
import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        int[] inputs = input();
//        int[] inputs = mockup();
        int swapCount = 0;

        for (int i = 0; i < inputs.length; i++) {
            for (int j = inputs.length - 1; j > i; j--) {
                if (inputs[j] < inputs[j-1]) {
                    swap(inputs, j, j-1);
                    swapCount++;
                }
            }
        }
        StringBuilder output = new StringBuilder();
        for (int i : inputs) {
            output.append(i + " ");
        }
        String outputString = output.toString();
        System.out.println(outputString.substring(0,outputString.length() - 1));
        System.out.println(swapCount);
    }

    private static int[] mockup() {
        int a[] = {1,2,3,4,5};
        return a;
    }

    private static void swap(int[] inputs, int j, int i) {
        int a = inputs[j];
        int b = inputs[i];
        inputs[i] = a;
        inputs[j] = b;
    }


    public static int[] input() {
        Scanner in = new Scanner(System.in);
        int count = in.nextInt();
        int[] inputs = new int[count];
        for (int i = 0; i < count; i++) {
            inputs[i] = in.nextInt();
        }
        in.close();
        return inputs;
    }

}