import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int count = 0;
        for(int i = 0; i < n; i++ ) {
            for(int j = n - 1; j > 0; j--) {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            }
        }

        System.out.print(arr[0]);
        for(int i = 1; i < n; i++) {
            System.out.print(" " + arr[i]);
        }

        System.out.println();
        System.out.println(count);

    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int count = 0;
        for(int i = 0; i < n; i++ ) {
            for(int j = n - 1; j > 0; j--) {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            }
        }

        System.out.print(arr[0]);
        for(int i = 1; i < n; i++) {
            System.out.print(" " + arr[i]);
        }

        System.out.println();
        System.out.println(count);

    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int count = 0;
        for(int i = 0; i < n; i++ ) {
            for(int j = n - 1; j > 0; j--) {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            }
        }

        System.out.print(arr[0]);
        for(int i = 1; i < n; i++) {
            System.out.print(" " + arr[i]);
        }

        System.out.println();
        System.out.println(count);

    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int count = 0;
        for(int i = 0; i < n; i++ ) {
            for(int j = n - 1; j > 0; j--) {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            }
        }

        System.out.print(arr[0]);
        for(int i = 1; i < n; i++) {
            System.out.print(" " + arr[i]);
        }

        System.out.println();
        System.out.println(count);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] arr = new int[n]; arr new int[n] n for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            arr[i] = sc.nextInt();
        } {
            arr[i] = sc.nextInt();
        } arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc int count = 0; count 0 for(int i = 0; i < n; i++ ) {
            for(int j = n - 1; j > 0; j--) {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            for(int j = n - 1; j > 0; j--) {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            }
        } {
            for(int j = n - 1; j > 0; j--) {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            }
        } for(int j = n - 1; j > 0; j--) {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            } int j = n - 1; int j = n - 1; j n - 1 n 1 j > 0 j 0 j-- j-- j {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            } {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            } if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                } arr[j] < arr[j-1] arr[j] arr j arr[j-1] arr j-1 j 1 {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                } int v = arr[j]; v arr[j] arr j arr[j] = arr[j-1] arr[j] arr j arr[j-1] arr j-1 j 1 arr[j-1] = v arr[j-1] arr j-1 j 1 v count++ count System.out.print(arr[0]) System.out.print System.out System System.out arr[0] arr 0 for(int i = 1; i < n; i++) {
            System.out.print(" " + arr[i]);
        } int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
            System.out.print(" " + arr[i]);
        } {
            System.out.print(" " + arr[i]);
        } System.out.print(" " + arr[i]) System.out.print System.out System System.out " " + arr[i] " " arr[i] arr i System.out.println() System.out.println System.out System System.out System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int count = 0;
        for(int i = 0; i < n; i++ ) {
            for(int j = n - 1; j > 0; j--) {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            }
        }

        System.out.print(arr[0]);
        for(int i = 1; i < n; i++) {
            System.out.print(" " + arr[i]);
        }

        System.out.println();
        System.out.println(count);

    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int count = 0;
        for(int i = 0; i < n; i++ ) {
            for(int j = n - 1; j > 0; j--) {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            }
        }

        System.out.print(arr[0]);
        for(int i = 1; i < n; i++) {
            System.out.print(" " + arr[i]);
        }

        System.out.println();
        System.out.println(count);

    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }

        int count = 0;
        for(int i = 0; i < n; i++ ) {
            for(int j = n - 1; j > 0; j--) {
                if(arr[j] < arr[j-1]) {
                    int v = arr[j];
                    arr[j] = arr[j-1];
                    arr[j-1] = v;
                    count++;
                }
            }
        }

        System.out.print(arr[0]);
        for(int i = 1; i < n; i++) {
            System.out.print(" " + arr[i]);
        }

        System.out.println();
        System.out.println(count);

    }
}