import java.util.Scanner;
class Main{
    public static void main(String[]arge){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int []A=new int[n];
        for(int i=0; i<n; i++){
            A[i]=sc.nextInt();
        }
        int flag,hozon,count=0;
        flag=1;
        while(flag==1){
            flag = 0;
            for(int j=n-1; j>0; j--){
                if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                }
                
            }        
            
     }
        for(int k=0; k<n; k++){
            
            if(k==n-1)System.out.print(A[k]);          
            if(k!=n-1)System.out.print(A[k]+" "); 
        }
            System.out.println("");
            System.out.println(count);   
   }
}     import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[]arge){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int []A=new int[n];
        for(int i=0; i<n; i++){
            A[i]=sc.nextInt();
        }
        int flag,hozon,count=0;
        flag=1;
        while(flag==1){
            flag = 0;
            for(int j=n-1; j>0; j--){
                if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                }
                
            }        
            
     }
        for(int k=0; k<n; k++){
            
            if(k==n-1)System.out.print(A[k]);          
            if(k!=n-1)System.out.print(A[k]+" "); 
        }
            System.out.println("");
            System.out.println(count);   
   }
} Main public static void main(String[]arge){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int []A=new int[n];
        for(int i=0; i<n; i++){
            A[i]=sc.nextInt();
        }
        int flag,hozon,count=0;
        flag=1;
        while(flag==1){
            flag = 0;
            for(int j=n-1; j>0; j--){
                if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                }
                
            }        
            
     }
        for(int k=0; k<n; k++){
            
            if(k==n-1)System.out.print(A[k]);          
            if(k!=n-1)System.out.print(A[k]+" "); 
        }
            System.out.println("");
            System.out.println(count);   
   } main {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int []A=new int[n];
        for(int i=0; i<n; i++){
            A[i]=sc.nextInt();
        }
        int flag,hozon,count=0;
        flag=1;
        while(flag==1){
            flag = 0;
            for(int j=n-1; j>0; j--){
                if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                }
                
            }        
            
     }
        for(int k=0; k<n; k++){
            
            if(k==n-1)System.out.print(A[k]);          
            if(k!=n-1)System.out.print(A[k]+" "); 
        }
            System.out.println("");
            System.out.println(count);   
   } Scanner sc=new Scanner(System.in); sc new Scanner(System.in) 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]=sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int flag flag hozon hozon count=0; count 0 flag=1 flag 1 while(flag==1){
            flag = 0;
            for(int j=n-1; j>0; j--){
                if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                }
                
            }        
            
     } flag==1 flag 1 {
            flag = 0;
            for(int j=n-1; j>0; j--){
                if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                }
                
            }        
            
     } flag = 0 flag 0 for(int j=n-1; j>0; j--){
                if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                }
                
            } int j=n-1; int j=n-1; j n-1 n 1 j>0 j 0 j-- j-- j {
                if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                }
                
            } {
                if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                }
                
            } if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                } A[j]<A[j-1] A[j] A j A[j-1] A j-1 j 1 {
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                } hozon=A[j] hozon A[j] A j A[j]=A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1]=hozon A[j-1] A j-1 j 1 hozon flag=1 flag 1 count+=1 count 1 for(int k=0; k<n; k++){
            
            if(k==n-1)System.out.print(A[k]);          
            if(k!=n-1)System.out.print(A[k]+" "); 
        } int k=0; int k=0; k 0 k<n k n k++ k++ k {
            
            if(k==n-1)System.out.print(A[k]);          
            if(k!=n-1)System.out.print(A[k]+" "); 
        } {
            
            if(k==n-1)System.out.print(A[k]);          
            if(k!=n-1)System.out.print(A[k]+" "); 
        } if(k==n-1)System.out.print(A[k]); k==n-1 k n-1 n 1 System.out.print(A[k]) System.out.print System.out System System.out A[k] A k if(k!=n-1)System.out.print(A[k]+" "); k!=n-1 k n-1 n 1 System.out.print(A[k]+" ") System.out.print System.out System System.out A[k]+" " A[k] A k " " System.out.println("") System.out.println System.out System System.out "" System.out.println(count) System.out.println System.out System System.out count String[]arge arge
import java.util.Scanner;
class Main{
    public static void main(String[]arge){
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int []A=new int[n];
        for(int i=0; i<n; i++){
            A[i]=sc.nextInt();
        }
        int flag,hozon,count=0;
        flag=1;
        while(flag==1){
            flag = 0;
            for(int j=n-1; j>0; j--){
                if(A[j]<A[j-1]){
                hozon=A[j];
                A[j]=A[j-1];
                A[j-1]=hozon;
                flag=1;
                count+=1;
                }
                
            }        
            
     }
        for(int k=0; k<n; k++){
            
            if(k==n-1)System.out.print(A[k]);          
            if(k!=n-1)System.out.print(A[k]+" "); 
        }
            System.out.println("");
            System.out.println(count);   
   }
}    