import java.util.Scanner;
import java.util.StringJoiner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = Integer.parseInt(scanner.next());
        }

        boolean flag = true;
        int swapCount = 0;
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(concat(array));
        System.out.println(swapCount);
    }

    private static String concat(int[] array) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int value : array) {
            joiner.add(String.valueOf(value));
        }
        return joiner.toString();
    }

    private static void swap(int i, int j, int[] array) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
} import java.util.Scanner; Scanner java.util import java.util.StringJoiner; StringJoiner java.util public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = Integer.parseInt(scanner.next());
        }

        boolean flag = true;
        int swapCount = 0;
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(concat(array));
        System.out.println(swapCount);
    }

    private static String concat(int[] array) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int value : array) {
            joiner.add(String.valueOf(value));
        }
        return joiner.toString();
    }

    private static void swap(int i, int j, int[] array) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
} Main public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = Integer.parseInt(scanner.next());
        }

        boolean flag = true;
        int swapCount = 0;
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(concat(array));
        System.out.println(swapCount);
    } main {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = Integer.parseInt(scanner.next());
        }

        boolean flag = true;
        int swapCount = 0;
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(concat(array));
        System.out.println(swapCount);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int size = Integer.parseInt(scanner.next()); size Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner int[] array = new int[size]; array new int[size] size for (int i = 0; i < size; i++) {
            array[i] = Integer.parseInt(scanner.next());
        } int i = 0; int i = 0; i 0 i < size i size i++ i++ i {
            array[i] = Integer.parseInt(scanner.next());
        } {
            array[i] = Integer.parseInt(scanner.next());
        } array[i] = Integer.parseInt(scanner.next()) array[i] array i Integer.parseInt(scanner.next()) Integer.parseInt Integer scanner.next() scanner.next scanner boolean flag = true; flag true int swapCount = 0; swapCount 0 while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            }
        } flag {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            }
        } flag = false flag false for (int j = size - 1; j > 0; j--) {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            } int j = size - 1; int j = size - 1; j size - 1 size 1 j > 0 j 0 j-- j-- j {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            } {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            } if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                } array[j] < array[j - 1] array[j] array j array[j - 1] array j - 1 j 1 {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                } swap(j, j - 1, array) swap j j - 1 j 1 array swapCount++ swapCount flag = true flag true System.out.println(concat(array)) System.out.println System.out System System.out concat(array) concat array System.out.println(swapCount) System.out.println System.out System System.out swapCount String[] args args private static String concat(int[] array) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int value : array) {
            joiner.add(String.valueOf(value));
        }
        return joiner.toString();
    } concat {
        StringJoiner joiner = new StringJoiner(" ");
        for (int value : array) {
            joiner.add(String.valueOf(value));
        }
        return joiner.toString();
    } StringJoiner joiner = new StringJoiner(" "); joiner new StringJoiner(" ") for (int value : array) {
            joiner.add(String.valueOf(value));
        } int value array {
            joiner.add(String.valueOf(value));
        } {
            joiner.add(String.valueOf(value));
        } joiner.add(String.valueOf(value)) joiner.add joiner String.valueOf(value) String.valueOf String value return joiner.toString(); joiner.toString() joiner.toString joiner int[] array array private static void swap(int i, int j, int[] array) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    } swap {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    } int temp = array[i]; temp array[i] array i array[i] = array[j] array[i] array i array[j] array j array[j] = temp array[j] array j temp int i i int j j int[] array array public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = Integer.parseInt(scanner.next());
        }

        boolean flag = true;
        int swapCount = 0;
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(concat(array));
        System.out.println(swapCount);
    }

    private static String concat(int[] array) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int value : array) {
            joiner.add(String.valueOf(value));
        }
        return joiner.toString();
    }

    private static void swap(int i, int j, int[] array) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
} public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = Integer.parseInt(scanner.next());
        }

        boolean flag = true;
        int swapCount = 0;
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(concat(array));
        System.out.println(swapCount);
    }

    private static String concat(int[] array) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int value : array) {
            joiner.add(String.valueOf(value));
        }
        return joiner.toString();
    }

    private static void swap(int i, int j, int[] array) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
} Main
import java.util.Scanner;
import java.util.StringJoiner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int size = Integer.parseInt(scanner.next());
        int[] array = new int[size];
        for (int i = 0; i < size; i++) {
            array[i] = Integer.parseInt(scanner.next());
        }

        boolean flag = true;
        int swapCount = 0;
        while (flag) {
            flag = false;
            for (int j = size - 1; j > 0; j--) {
                if (array[j] < array[j - 1]) {
                    swap(j, j - 1, array);
                    swapCount++;
                    flag = true;
                }
            }
        }
        System.out.println(concat(array));
        System.out.println(swapCount);
    }

    private static String concat(int[] array) {
        StringJoiner joiner = new StringJoiner(" ");
        for (int value : array) {
            joiner.add(String.valueOf(value));
        }
        return joiner.toString();
    }

    private static void swap(int i, int j, int[] array) {
        int temp = array[i];
        array[i] = array[j];
        array[j] = temp;
    }
}