import java.util.Scanner;

public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        boolean flag=true;
        int counter=0;
        while(flag){
            flag=false;
            for(int j=n-1;j>=1;j--){
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            }        
        }
        for(int i=0;i<=n-2;i++) System.out.printf("%d ",a[i]);
        System.out.println(a[n-1]);
        System.out.println(counter);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        boolean flag=true;
        int counter=0;
        while(flag){
            flag=false;
            for(int j=n-1;j>=1;j--){
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            }        
        }
        for(int i=0;i<=n-2;i++) System.out.printf("%d ",a[i]);
        System.out.println(a[n-1]);
        System.out.println(counter);
    }
} Main private static Scanner sc=new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args){
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        boolean flag=true;
        int counter=0;
        while(flag){
            flag=false;
            for(int j=n-1;j>=1;j--){
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            }        
        }
        for(int i=0;i<=n-2;i++) System.out.printf("%d ",a[i]);
        System.out.println(a[n-1]);
        System.out.println(counter);
    } main {
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        boolean flag=true;
        int counter=0;
        while(flag){
            flag=false;
            for(int j=n-1;j>=1;j--){
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            }        
        }
        for(int i=0;i<=n-2;i++) System.out.printf("%d ",a[i]);
        System.out.println(a[n-1]);
        System.out.println(counter);
    } int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] a=new int[n]; a new int[n] n for(int i=0;i<n;i++) a[i]=sc.nextInt(); int i=0; int i=0; i 0 i<n i n i++ i++ i a[i]=sc.nextInt(); a[i]=sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc boolean flag=true; flag true int counter=0; counter 0 while(flag){
            flag=false;
            for(int j=n-1;j>=1;j--){
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            }        
        } flag {
            flag=false;
            for(int j=n-1;j>=1;j--){
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            }        
        } flag=false flag false for(int j=n-1;j>=1;j--){
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            } int j=n-1; int j=n-1; j n-1 n 1 j>=1 j 1 j-- j-- j {
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            } {
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            } if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                } a[j]<a[j-1] a[j] a j a[j-1] a j-1 j 1 {
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                } int 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 counter++ counter flag=true flag true for(int i=0;i<=n-2;i++) System.out.printf("%d ",a[i]); int i=0; int i=0; i 0 i<=n-2 i n-2 n 2 i++ i++ i System.out.printf("%d ",a[i]); System.out.printf("%d ",a[i]) System.out.printf System.out System System.out "%d " 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(counter) System.out.println System.out System System.out counter String[] args args public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        boolean flag=true;
        int counter=0;
        while(flag){
            flag=false;
            for(int j=n-1;j>=1;j--){
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            }        
        }
        for(int i=0;i<=n-2;i++) System.out.printf("%d ",a[i]);
        System.out.println(a[n-1]);
        System.out.println(counter);
    }
} public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        boolean flag=true;
        int counter=0;
        while(flag){
            flag=false;
            for(int j=n-1;j>=1;j--){
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            }        
        }
        for(int i=0;i<=n-2;i++) System.out.printf("%d ",a[i]);
        System.out.println(a[n-1]);
        System.out.println(counter);
    }
} Main
import java.util.Scanner;

public class Main {
    private static Scanner sc=new Scanner(System.in);
    public static void main(String[] args){
        int n=sc.nextInt();
        int[] a=new int[n];
        for(int i=0;i<n;i++) a[i]=sc.nextInt();
        boolean flag=true;
        int counter=0;
        while(flag){
            flag=false;
            for(int j=n-1;j>=1;j--){
                if(a[j]<a[j-1]){
                    int t=a[j];
                    a[j]=a[j-1];
                    a[j-1]=t;
                    counter++;
                    flag=true;
                }
            }        
        }
        for(int i=0;i<=n-2;i++) System.out.printf("%d ",a[i]);
        System.out.println(a[n-1]);
        System.out.println(counter);
    }
}