import java.util.Scanner;

class Main{

    static int bubbleSort(int[] a, int n){
        boolean flag = true;
        int cnt = 0;
        while(flag){
            flag = false;
            for(int j = n - 1; j >= 1; j--){
                if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                }
            }
        }
        return cnt;
    }

    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);

        int n = scn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scn.nextInt();
        }

        int cnt = bubbleSort(a, n);

        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(cnt);
    }
}
 import java.util.Scanner; Scanner java.util class Main{

    static int bubbleSort(int[] a, int n){
        boolean flag = true;
        int cnt = 0;
        while(flag){
            flag = false;
            for(int j = n - 1; j >= 1; j--){
                if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                }
            }
        }
        return cnt;
    }

    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);

        int n = scn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scn.nextInt();
        }

        int cnt = bubbleSort(a, n);

        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(cnt);
    }
} Main static int bubbleSort(int[] a, int n){
        boolean flag = true;
        int cnt = 0;
        while(flag){
            flag = false;
            for(int j = n - 1; j >= 1; j--){
                if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                }
            }
        }
        return cnt;
    } bubbleSort {
        boolean flag = true;
        int cnt = 0;
        while(flag){
            flag = false;
            for(int j = n - 1; j >= 1; j--){
                if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                }
            }
        }
        return cnt;
    } boolean flag = true; flag true int cnt = 0; cnt 0 while(flag){
            flag = false;
            for(int j = n - 1; j >= 1; j--){
                if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                }
            }
        } flag {
            flag = false;
            for(int j = n - 1; j >= 1; j--){
                if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                }
            }
        } flag = false flag false for(int j = n - 1; j >= 1; j--){
                if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                }
            } int j = n - 1; int j = n - 1; j n - 1 n 1 j >= 1 j 1 j-- j-- j {
                if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                }
            } {
                if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                }
            } if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                } a[j-1] > a[j] a[j-1] a j-1 j 1 a[j] a j {
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                } int tmp = a[j]; tmp a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1] = tmp a[j-1] a j-1 j 1 tmp flag = true flag true cnt++ cnt return cnt; cnt int[] a a int n n public static void main(String[] args){
        Scanner scn = new Scanner(System.in);

        int n = scn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scn.nextInt();
        }

        int cnt = bubbleSort(a, n);

        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(cnt);
    } main {
        Scanner scn = new Scanner(System.in);

        int n = scn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scn.nextInt();
        }

        int cnt = bubbleSort(a, n);

        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(cnt);
    } Scanner scn = new Scanner(System.in); scn new Scanner(System.in) int n = scn.nextInt(); n scn.nextInt() scn.nextInt scn int[] a = new int[n]; a new int[n] n for(int i = 0; i < n; i++){
            a[i] = scn.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            a[i] = scn.nextInt();
        } {
            a[i] = scn.nextInt();
        } a[i] = scn.nextInt() a[i] a i scn.nextInt() scn.nextInt scn int cnt = bubbleSort(a, n); cnt bubbleSort(a, n) bubbleSort a n for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        } int i = 0; int i = 0; i 0 i < n-1 i n-1 n 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[n-1]) System.out.println System.out System System.out a[n-1] a n-1 n 1 System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args
import java.util.Scanner;

class Main{

    static int bubbleSort(int[] a, int n){
        boolean flag = true;
        int cnt = 0;
        while(flag){
            flag = false;
            for(int j = n - 1; j >= 1; j--){
                if(a[j-1] > a[j]){
                    int tmp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = tmp;

                    flag = true;
                    cnt++;
                }
            }
        }
        return cnt;
    }

    public static void main(String[] args){
        Scanner scn = new Scanner(System.in);

        int n = scn.nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++){
            a[i] = scn.nextInt();
        }

        int cnt = bubbleSort(a, n);

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

