
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());

        String[] a = sc.nextLine().split(" ");
        int[] array = new int[num];
        for (int i = 0; i < num; i++) {
            array[i] = Integer.parseInt(a[i]);
        }

        int changeCount = 0;

        boolean loopFlg = true;
        while (loopFlg) {
            loopFlg = false;
            for (int i = num - 1; i >= 1; i--) {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            }
    
        }
        
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        }
        System.out.println();

        System.out.println(changeCount);
    }
}

/**
1 bubbleSort(A, N) // N 個の要素を含む 0-オリジンの配列 A
2   flag = 1 // 逆の隣接要素が存在する
3   while flag
4     flag = 0
5     for j が N-1 から 1 まで
6       if A[j] < A[j-1]
7         A[j] と A[j-1] を交換
8         flag = 1

入力例 1
5
5 3 2 4 1
出力例 1
1 2 3 4 5
8
 */ import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());

        String[] a = sc.nextLine().split(" ");
        int[] array = new int[num];
        for (int i = 0; i < num; i++) {
            array[i] = Integer.parseInt(a[i]);
        }

        int changeCount = 0;

        boolean loopFlg = true;
        while (loopFlg) {
            loopFlg = false;
            for (int i = num - 1; i >= 1; i--) {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            }
    
        }
        
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        }
        System.out.println();

        System.out.println(changeCount);
    }
} Main public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());

        String[] a = sc.nextLine().split(" ");
        int[] array = new int[num];
        for (int i = 0; i < num; i++) {
            array[i] = Integer.parseInt(a[i]);
        }

        int changeCount = 0;

        boolean loopFlg = true;
        while (loopFlg) {
            loopFlg = false;
            for (int i = num - 1; i >= 1; i--) {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            }
    
        }
        
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        }
        System.out.println();

        System.out.println(changeCount);
    } main {

        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());

        String[] a = sc.nextLine().split(" ");
        int[] array = new int[num];
        for (int i = 0; i < num; i++) {
            array[i] = Integer.parseInt(a[i]);
        }

        int changeCount = 0;

        boolean loopFlg = true;
        while (loopFlg) {
            loopFlg = false;
            for (int i = num - 1; i >= 1; i--) {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            }
    
        }
        
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        }
        System.out.println();

        System.out.println(changeCount);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = Integer.parseInt(sc.nextLine()); num Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc String[] a = sc.nextLine().split(" "); a sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int[] array = new int[num]; array new int[num] num for (int i = 0; i < num; i++) {
            array[i] = Integer.parseInt(a[i]);
        } int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
            array[i] = Integer.parseInt(a[i]);
        } {
            array[i] = Integer.parseInt(a[i]);
        } array[i] = Integer.parseInt(a[i]) array[i] array i Integer.parseInt(a[i]) Integer.parseInt Integer a[i] a i int changeCount = 0; changeCount 0 boolean loopFlg = true; loopFlg true while (loopFlg) {
            loopFlg = false;
            for (int i = num - 1; i >= 1; i--) {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            }
    
        } loopFlg {
            loopFlg = false;
            for (int i = num - 1; i >= 1; i--) {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            }
    
        } loopFlg = false loopFlg false for (int i = num - 1; i >= 1; i--) {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            } int i = num - 1; int i = num - 1; i num - 1 num 1 i >= 1 i 1 i-- i-- i {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            } {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            } if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                } array[i] < array[i-1] array[i] array i array[i-1] array i-1 i 1 {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                } int tmp = array[i]; tmp array[i] array i array[i] = array[i-1] array[i] array i array[i-1] array i-1 i 1 array[i-1] = tmp array[i-1] array i-1 i 1 tmp changeCount++ changeCount loopFlg = true loopFlg true for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        } int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        } {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        } System.out.print(array[i]) System.out.print System.out System System.out array[i] array i if (i!=array.length-1) {
                System.out.print(" ");
            } i!=array.length-1 i array.length-1 array.length array array.length 1 {
                System.out.print(" ");
            } System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out System.out.println(changeCount) System.out.println System.out System System.out changeCount String[] args args public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());

        String[] a = sc.nextLine().split(" ");
        int[] array = new int[num];
        for (int i = 0; i < num; i++) {
            array[i] = Integer.parseInt(a[i]);
        }

        int changeCount = 0;

        boolean loopFlg = true;
        while (loopFlg) {
            loopFlg = false;
            for (int i = num - 1; i >= 1; i--) {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            }
    
        }
        
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        }
        System.out.println();

        System.out.println(changeCount);
    }
} public class Main {
    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());

        String[] a = sc.nextLine().split(" ");
        int[] array = new int[num];
        for (int i = 0; i < num; i++) {
            array[i] = Integer.parseInt(a[i]);
        }

        int changeCount = 0;

        boolean loopFlg = true;
        while (loopFlg) {
            loopFlg = false;
            for (int i = num - 1; i >= 1; i--) {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            }
    
        }
        
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        }
        System.out.println();

        System.out.println(changeCount);
    }
} Main

import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);
        int num = Integer.parseInt(sc.nextLine());

        String[] a = sc.nextLine().split(" ");
        int[] array = new int[num];
        for (int i = 0; i < num; i++) {
            array[i] = Integer.parseInt(a[i]);
        }

        int changeCount = 0;

        boolean loopFlg = true;
        while (loopFlg) {
            loopFlg = false;
            for (int i = num - 1; i >= 1; i--) {
                if (array[i] < array[i-1]) {
                    int tmp = array[i];
                    array[i] = array[i-1];
                    array[i-1] = tmp;
                    changeCount++;
                    loopFlg = true;
                }
            }
    
        }
        
        for (int i = 0; i < array.length; i++) {
            System.out.print(array[i]);
            if (i!=array.length-1) {
                System.out.print(" ");
            }
        }
        System.out.println();

        System.out.println(changeCount);
    }
}

/**
1 bubbleSort(A, N) // N 個の要素を含む 0-オリジンの配列 A
2   flag = 1 // 逆の隣接要素が存在する
3   while flag
4     flag = 0
5     for j が N-1 から 1 まで
6       if A[j] < A[j-1]
7         A[j] と A[j-1] を交換
8         flag = 1

入力例 1
5
5 3 2 4 1
出力例 1
1 2 3 4 5
8
 */
