import java.util.Scanner;

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

        int N = sc.nextInt();
        int i ,j ,count = 0 ,a;
        int array[] = new int[N];

        for(i = 0;i < N;i++){
            array[i] = sc.nextInt();
        }

        for(i = N - 1;i > 0;i--){
            for(j = N - 1;j >= N - i;j--){
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            }
        }

        for(i = 0;i < N;i++){
            if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            }
        }

        System.out.printf("%d\n",count);

    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int i ,j ,count = 0 ,a;
        int array[] = new int[N];

        for(i = 0;i < N;i++){
            array[i] = sc.nextInt();
        }

        for(i = N - 1;i > 0;i--){
            for(j = N - 1;j >= N - i;j--){
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            }
        }

        for(i = 0;i < N;i++){
            if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            }
        }

        System.out.printf("%d\n",count);

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

        int N = sc.nextInt();
        int i ,j ,count = 0 ,a;
        int array[] = new int[N];

        for(i = 0;i < N;i++){
            array[i] = sc.nextInt();
        }

        for(i = N - 1;i > 0;i--){
            for(j = N - 1;j >= N - i;j--){
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            }
        }

        for(i = 0;i < N;i++){
            if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            }
        }

        System.out.printf("%d\n",count);

    } main {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int i ,j ,count = 0 ,a;
        int array[] = new int[N];

        for(i = 0;i < N;i++){
            array[i] = sc.nextInt();
        }

        for(i = N - 1;i > 0;i--){
            for(j = N - 1;j >= N - i;j--){
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            }
        }

        for(i = 0;i < N;i++){
            if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            }
        }

        System.out.printf("%d\n",count);

    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int i i j j count = 0 count 0 a; a int array[] = new int[N]; array new int[N] N for(i = 0;i < N;i++){
            array[i] = sc.nextInt();
        } i = 0; i = 0 i 0 i < N i N i++ i++ i {
            array[i] = sc.nextInt();
        } {
            array[i] = sc.nextInt();
        } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc for(i = N - 1;i > 0;i--){
            for(j = N - 1;j >= N - i;j--){
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            }
        } i = N - 1; i = N - 1 i N - 1 N 1 i > 0 i 0 i-- i-- i {
            for(j = N - 1;j >= N - i;j--){
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            }
        } {
            for(j = N - 1;j >= N - i;j--){
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            }
        } for(j = N - 1;j >= N - i;j--){
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            } j = N - 1; j = N - 1 j N - 1 N 1 j >= N - i j N - i N i j-- j-- j {
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            } {
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            } if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                } array[j] < array[j-1] array[j] array j array[j-1] array j-1 j 1 {
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                } a = array[j] a array[j] array j array[j] = array[j-1] array[j] array j array[j-1] array j-1 j 1 array[j-1] = a array[j-1] array j-1 j 1 a count++ count for(i = 0;i < N;i++){
            if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            }
        } i = 0; i = 0 i 0 i < N i N i++ i++ i {
            if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            }
        } {
            if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            }
        } if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            } i <= N-2 i N-2 N 2 {
                System.out.printf("%d ",array[i]);
            } System.out.printf("%d ",array[i]) System.out.printf System.out System System.out "%d " array[i] array i {
                System.out.printf("%d\n",array[i]);
            } System.out.printf("%d\n",array[i]) System.out.printf System.out System System.out "%d\n" array[i] array i System.out.printf("%d\n",count) System.out.printf System.out System System.out "%d\n" count String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int i ,j ,count = 0 ,a;
        int array[] = new int[N];

        for(i = 0;i < N;i++){
            array[i] = sc.nextInt();
        }

        for(i = N - 1;i > 0;i--){
            for(j = N - 1;j >= N - i;j--){
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            }
        }

        for(i = 0;i < N;i++){
            if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            }
        }

        System.out.printf("%d\n",count);

    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int i ,j ,count = 0 ,a;
        int array[] = new int[N];

        for(i = 0;i < N;i++){
            array[i] = sc.nextInt();
        }

        for(i = N - 1;i > 0;i--){
            for(j = N - 1;j >= N - i;j--){
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            }
        }

        for(i = 0;i < N;i++){
            if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            }
        }

        System.out.printf("%d\n",count);

    }
} Main
import java.util.Scanner;

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

        int N = sc.nextInt();
        int i ,j ,count = 0 ,a;
        int array[] = new int[N];

        for(i = 0;i < N;i++){
            array[i] = sc.nextInt();
        }

        for(i = N - 1;i > 0;i--){
            for(j = N - 1;j >= N - i;j--){
                if(array[j] < array[j-1]){
                    a = array[j];
                    array[j] = array[j-1];
                    array[j-1] = a;
                    count++;
                }
            }
        }

        for(i = 0;i < N;i++){
            if(i <= N-2){
                System.out.printf("%d ",array[i]);
            }else{
                System.out.printf("%d\n",array[i]);
            }
        }

        System.out.printf("%d\n",count);

    }
}
