
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] ints=new int[n];
        for(int i=0;i<n;i++){
            ints[i]=scanner.nextInt();
        }
        int result=bubbleSort(ints);
        for(int i=0;i<ints.length;i++){
            System.out.print(ints[i]);
            if(i!=ints.length-1){
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(result);
    }
    public static int bubbleSort(int[] ints){
        int result=0;
        for(int i=ints.length;i>1;i--){
            for(int j=ints.length-1;j>ints.length-i;j--){
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            }
        }
        return result;
    }

}
 import java.util.Scanner; Scanner java.util public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] ints=new int[n];
        for(int i=0;i<n;i++){
            ints[i]=scanner.nextInt();
        }
        int result=bubbleSort(ints);
        for(int i=0;i<ints.length;i++){
            System.out.print(ints[i]);
            if(i!=ints.length-1){
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(result);
    }
    public static int bubbleSort(int[] ints){
        int result=0;
        for(int i=ints.length;i>1;i--){
            for(int j=ints.length-1;j>ints.length-i;j--){
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            }
        }
        return result;
    }

} Main public static void main(String[] args) {
        // write your code here
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] ints=new int[n];
        for(int i=0;i<n;i++){
            ints[i]=scanner.nextInt();
        }
        int result=bubbleSort(ints);
        for(int i=0;i<ints.length;i++){
            System.out.print(ints[i]);
            if(i!=ints.length-1){
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(result);
    } main {
        // write your code here
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] ints=new int[n];
        for(int i=0;i<n;i++){
            ints[i]=scanner.nextInt();
        }
        int result=bubbleSort(ints);
        for(int i=0;i<ints.length;i++){
            System.out.print(ints[i]);
            if(i!=ints.length-1){
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(result);
    } Scanner scanner=new Scanner(System.in); scanner new Scanner(System.in) int n=scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int[] ints=new int[n]; ints new int[n] n for(int i=0;i<n;i++){
            ints[i]=scanner.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            ints[i]=scanner.nextInt();
        } {
            ints[i]=scanner.nextInt();
        } ints[i]=scanner.nextInt() ints[i] ints i scanner.nextInt() scanner.nextInt scanner int result=bubbleSort(ints); result bubbleSort(ints) bubbleSort ints for(int i=0;i<ints.length;i++){
            System.out.print(ints[i]);
            if(i!=ints.length-1){
                System.out.print(" ");
            }
        } int i=0; int i=0; i 0 i<ints.length i ints.length ints ints.length i++ i++ i {
            System.out.print(ints[i]);
            if(i!=ints.length-1){
                System.out.print(" ");
            }
        } {
            System.out.print(ints[i]);
            if(i!=ints.length-1){
                System.out.print(" ");
            }
        } System.out.print(ints[i]) System.out.print System.out System System.out ints[i] ints i if(i!=ints.length-1){
                System.out.print(" ");
            } i!=ints.length-1 i ints.length-1 ints.length ints ints.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(result) System.out.println System.out System System.out result String[] args args public static int bubbleSort(int[] ints){
        int result=0;
        for(int i=ints.length;i>1;i--){
            for(int j=ints.length-1;j>ints.length-i;j--){
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            }
        }
        return result;
    } bubbleSort {
        int result=0;
        for(int i=ints.length;i>1;i--){
            for(int j=ints.length-1;j>ints.length-i;j--){
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            }
        }
        return result;
    } int result=0; result 0 for(int i=ints.length;i>1;i--){
            for(int j=ints.length-1;j>ints.length-i;j--){
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            }
        } int i=ints.length; int i=ints.length; i ints.length ints ints.length i>1 i 1 i-- i-- i {
            for(int j=ints.length-1;j>ints.length-i;j--){
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            }
        } {
            for(int j=ints.length-1;j>ints.length-i;j--){
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            }
        } for(int j=ints.length-1;j>ints.length-i;j--){
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            } int j=ints.length-1; int j=ints.length-1; j ints.length-1 ints.length ints ints.length 1 j>ints.length-i j ints.length-i ints.length ints ints.length i j-- j-- j {
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            } {
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            } if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                } ints[j]<ints[j-1] ints[j] ints j ints[j-1] ints j-1 j 1 {
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                } int tmp=ints[j]; tmp ints[j] ints j ints[j]=ints[j-1] ints[j] ints j ints[j-1] ints j-1 j 1 ints[j-1]=tmp ints[j-1] ints j-1 j 1 tmp result++ result return result; result int[] ints ints public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] ints=new int[n];
        for(int i=0;i<n;i++){
            ints[i]=scanner.nextInt();
        }
        int result=bubbleSort(ints);
        for(int i=0;i<ints.length;i++){
            System.out.print(ints[i]);
            if(i!=ints.length-1){
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(result);
    }
    public static int bubbleSort(int[] ints){
        int result=0;
        for(int i=ints.length;i>1;i--){
            for(int j=ints.length-1;j>ints.length-i;j--){
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            }
        }
        return result;
    }

} public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] ints=new int[n];
        for(int i=0;i<n;i++){
            ints[i]=scanner.nextInt();
        }
        int result=bubbleSort(ints);
        for(int i=0;i<ints.length;i++){
            System.out.print(ints[i]);
            if(i!=ints.length-1){
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(result);
    }
    public static int bubbleSort(int[] ints){
        int result=0;
        for(int i=ints.length;i>1;i--){
            for(int j=ints.length-1;j>ints.length-i;j--){
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            }
        }
        return result;
    }

} Main

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int[] ints=new int[n];
        for(int i=0;i<n;i++){
            ints[i]=scanner.nextInt();
        }
        int result=bubbleSort(ints);
        for(int i=0;i<ints.length;i++){
            System.out.print(ints[i]);
            if(i!=ints.length-1){
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(result);
    }
    public static int bubbleSort(int[] ints){
        int result=0;
        for(int i=ints.length;i>1;i--){
            for(int j=ints.length-1;j>ints.length-i;j--){
                if(ints[j]<ints[j-1]){
                    int tmp=ints[j];
                    ints[j]=ints[j-1];
                    ints[j-1]=tmp;
                    result++;
                }
            }
        }
        return result;
    }

}

