import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a=new int[101];
        int i,t,j,n,co=0;
        n = sc.nextInt();
        for(i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        for(i=n-1;i>0;i--){
            for(j=n-1;j>=n-i;j--){
                if(a[j]<a[j-1]){
                    t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    co++;
                }

            }
        }

        for(i=0;i<n;i++){
            if(i==0)System.out.print(a[i]);
            else System.out.print(" "+a[i]);
        }
        System.out.println();
        System.out.println(co);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a=new int[101];
        int i,t,j,n,co=0;
        n = sc.nextInt();
        for(i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        for(i=n-1;i>0;i--){
            for(j=n-1;j>=n-i;j--){
                if(a[j]<a[j-1]){
                    t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    co++;
                }

            }
        }

        for(i=0;i<n;i++){
            if(i==0)System.out.print(a[i]);
            else System.out.print(" "+a[i]);
        }
        System.out.println();
        System.out.println(co);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a=new int[101];
        int i,t,j,n,co=0;
        n = sc.nextInt();
        for(i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        for(i=n-1;i>0;i--){
            for(j=n-1;j>=n-i;j--){
                if(a[j]<a[j-1]){
                    t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    co++;
                }

            }
        }

        for(i=0;i<n;i++){
            if(i==0)System.out.print(a[i]);
            else System.out.print(" "+a[i]);
        }
        System.out.println();
        System.out.println(co);
    } main {
        Scanner sc = new Scanner(System.in);
        int[] a=new int[101];
        int i,t,j,n,co=0;
        n = sc.nextInt();
        for(i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        for(i=n-1;i>0;i--){
            for(j=n-1;j>=n-i;j--){
                if(a[j]<a[j-1]){
                    t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    co++;
                }

            }
        }

        for(i=0;i<n;i++){
            if(i==0)System.out.print(a[i]);
            else System.out.print(" "+a[i]);
        }
        System.out.println();
        System.out.println(co);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int[] a=new int[101]; a new int[101] 101 int i i t t j j n n co=0; co 0 n = sc.nextInt() n sc.nextInt() sc.nextInt sc for(i=0;i<n;i++){
            a[i] = sc.nextInt();
        } i=0; i=0 i 0 i<n i n i++ i++ i {
            a[i] = sc.nextInt();
        } {
            a[i] = sc.nextInt();
        } a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc for(i=n-1;i>0;i--){
            for(j=n-1;j>=n-i;j--){
                if(a[j]<a[j-1]){
                    t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    co++;
                }

            }
        } 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(a[j]<a[j-1]){
                    t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    co++;
                }

            }
        } {
            for(j=n-1;j>=n-i;j--){
                if(a[j]<a[j-1]){
                    t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    co++;
                }

            }
        } for(j=n-1;j>=n-i;j--){
                if(a[j]<a[j-1]){
                    t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    co++;
                }

            } j=n-1; j=n-1 j n-1 n 1 j>=n-i j n-i n i j-- j-- j {
                if(a[j]<a[j-1]){
                    t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    co++;
                }

            } {
                if(a[j]<a[j-1]){
                    t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    co++;
                }

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

            }
        }

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

            }
        }

        for(i=0;i<n;i++){
            if(i==0)System.out.print(a[i]);
            else System.out.print(" "+a[i]);
        }
        System.out.println();
        System.out.println(co);
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int[] a=new int[101];
        int i,t,j,n,co=0;
        n = sc.nextInt();
        for(i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        for(i=n-1;i>0;i--){
            for(j=n-1;j>=n-i;j--){
                if(a[j]<a[j-1]){
                    t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    co++;
                }

            }
        }

        for(i=0;i<n;i++){
            if(i==0)System.out.print(a[i]);
            else System.out.print(" "+a[i]);
        }
        System.out.println();
        System.out.println(co);
    }
}
