import java.util.Scanner;

 class Main{
	
public static int bubbleSort(int A[],int N){
    int i,j,r=0,temp;
    boolean flag=true;
    for(i=0;flag;i++){
    	flag=false;
        for(j=N-1;j>=i+1;j--){
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
}
}
    return r;
}
   
public static void main(String[] args){
         
		 Scanner sc= new Scanner(System.in);
	         int N=sc.nextInt();
             int A[]=new int[100];
             
             int i,j;
             for(i=0;i<N;i++){
            	 A[i] = sc.nextInt();
             }
	       
        int loop = bubbleSort(A,N);
        for(i=0;i<N;i++){
      	  if(i>0)
      	   System.out.print(" ");
         System.out.print(A[i]);
        }
        System.out.println();
        System.out.println(loop);
        sc.close();
}
} import java.util.Scanner; Scanner java.util class Main{
	
public static int bubbleSort(int A[],int N){
    int i,j,r=0,temp;
    boolean flag=true;
    for(i=0;flag;i++){
    	flag=false;
        for(j=N-1;j>=i+1;j--){
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
}
}
    return r;
}
   
public static void main(String[] args){
         
		 Scanner sc= new Scanner(System.in);
	         int N=sc.nextInt();
             int A[]=new int[100];
             
             int i,j;
             for(i=0;i<N;i++){
            	 A[i] = sc.nextInt();
             }
	       
        int loop = bubbleSort(A,N);
        for(i=0;i<N;i++){
      	  if(i>0)
      	   System.out.print(" ");
         System.out.print(A[i]);
        }
        System.out.println();
        System.out.println(loop);
        sc.close();
}
} Main public static int bubbleSort(int A[],int N){
    int i,j,r=0,temp;
    boolean flag=true;
    for(i=0;flag;i++){
    	flag=false;
        for(j=N-1;j>=i+1;j--){
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
}
}
    return r;
} bubbleSort {
    int i,j,r=0,temp;
    boolean flag=true;
    for(i=0;flag;i++){
    	flag=false;
        for(j=N-1;j>=i+1;j--){
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
}
}
    return r;
} int i i j j r=0 r 0 temp; temp boolean flag=true; flag true for(i=0;flag;i++){
    	flag=false;
        for(j=N-1;j>=i+1;j--){
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
}
} i=0; i=0 i 0 flag i++ i++ i {
    	flag=false;
        for(j=N-1;j>=i+1;j--){
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
}
} {
    	flag=false;
        for(j=N-1;j>=i+1;j--){
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
}
} flag=false flag false for(j=N-1;j>=i+1;j--){
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
} j=N-1; j=N-1 j N-1 N 1 j>=i+1 j i+1 i 1 j-- j-- j {
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
} {
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
} if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        } A[j]<A[j-1] A[j] A j A[j-1] A j-1 j 1 {
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        } temp=A[j] temp A[j] A j A[j]=A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1]=temp A[j-1] A j-1 j 1 temp flag=true flag true r++ r return r; r int A[] A int N N public static void main(String[] args){
         
		 Scanner sc= new Scanner(System.in);
	         int N=sc.nextInt();
             int A[]=new int[100];
             
             int i,j;
             for(i=0;i<N;i++){
            	 A[i] = sc.nextInt();
             }
	       
        int loop = bubbleSort(A,N);
        for(i=0;i<N;i++){
      	  if(i>0)
      	   System.out.print(" ");
         System.out.print(A[i]);
        }
        System.out.println();
        System.out.println(loop);
        sc.close();
} main {
         
		 Scanner sc= new Scanner(System.in);
	         int N=sc.nextInt();
             int A[]=new int[100];
             
             int i,j;
             for(i=0;i<N;i++){
            	 A[i] = sc.nextInt();
             }
	       
        int loop = bubbleSort(A,N);
        for(i=0;i<N;i++){
      	  if(i>0)
      	   System.out.print(" ");
         System.out.print(A[i]);
        }
        System.out.println();
        System.out.println(loop);
        sc.close();
} 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[100]; A new int[100] 100 int i i j; j 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 int loop = bubbleSort(A,N); loop bubbleSort(A,N) bubbleSort A N for(i=0;i<N;i++){
      	  if(i>0)
      	   System.out.print(" ");
         System.out.print(A[i]);
        } i=0; i=0 i 0 i<N i N i++ i++ i {
      	  if(i>0)
      	   System.out.print(" ");
         System.out.print(A[i]);
        } {
      	  if(i>0)
      	   System.out.print(" ");
         System.out.print(A[i]);
        } if(i>0)
      	   System.out.print(" "); i>0 i 0 System.out.print(" ") System.out.print System.out System System.out " " System.out.print(A[i]) System.out.print System.out System System.out A[i] A i System.out.println() System.out.println System.out System System.out System.out.println(loop) System.out.println System.out System System.out loop sc.close() sc.close sc String[] args args
import java.util.Scanner;

 class Main{
	
public static int bubbleSort(int A[],int N){
    int i,j,r=0,temp;
    boolean flag=true;
    for(i=0;flag;i++){
    	flag=false;
        for(j=N-1;j>=i+1;j--){
        	if(A[j]<A[j-1]){
        		temp=A[j];
        		A[j]=A[j-1];
        		A[j-1]=temp;
        flag=true;
        r++;      	
        }
}
}
    return r;
}
   
public static void main(String[] args){
         
		 Scanner sc= new Scanner(System.in);
	         int N=sc.nextInt();
             int A[]=new int[100];
             
             int i,j;
             for(i=0;i<N;i++){
            	 A[i] = sc.nextInt();
             }
	       
        int loop = bubbleSort(A,N);
        for(i=0;i<N;i++){
      	  if(i>0)
      	   System.out.print(" ");
         System.out.print(A[i]);
        }
        System.out.println();
        System.out.println(loop);
        sc.close();
}
}