import java.util.Scanner;
public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int kazu,i,j,cnt=0,hz;
		Scanner sca = new Scanner(System.in);
		kazu=sca.nextInt();
		int hai[]=new int[kazu];
		for(i=0;i<kazu;i++){
			hai[i]=sca.nextInt();
		}
       for(i=0;i<kazu-1;i++){
    	   for(j=kazu-1;j>0;j--){
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   }
	}
     for(i=0;i<kazu;i++){
    if(i!=kazu-1){	 
     System.out.print(hai[i]+" ");
     }else{
    	 System.out.println(hai[i]);
     }
     }
     System.out.println(cnt);

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int kazu,i,j,cnt=0,hz;
		Scanner sca = new Scanner(System.in);
		kazu=sca.nextInt();
		int hai[]=new int[kazu];
		for(i=0;i<kazu;i++){
			hai[i]=sca.nextInt();
		}
       for(i=0;i<kazu-1;i++){
    	   for(j=kazu-1;j>0;j--){
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   }
	}
     for(i=0;i<kazu;i++){
    if(i!=kazu-1){	 
     System.out.print(hai[i]+" ");
     }else{
    	 System.out.println(hai[i]);
     }
     }
     System.out.println(cnt);

}
} Main public static void main(String[] args) {
		// TODO Auto-generated method stub
		int kazu,i,j,cnt=0,hz;
		Scanner sca = new Scanner(System.in);
		kazu=sca.nextInt();
		int hai[]=new int[kazu];
		for(i=0;i<kazu;i++){
			hai[i]=sca.nextInt();
		}
       for(i=0;i<kazu-1;i++){
    	   for(j=kazu-1;j>0;j--){
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   }
	}
     for(i=0;i<kazu;i++){
    if(i!=kazu-1){	 
     System.out.print(hai[i]+" ");
     }else{
    	 System.out.println(hai[i]);
     }
     }
     System.out.println(cnt);

} main {
		// TODO Auto-generated method stub
		int kazu,i,j,cnt=0,hz;
		Scanner sca = new Scanner(System.in);
		kazu=sca.nextInt();
		int hai[]=new int[kazu];
		for(i=0;i<kazu;i++){
			hai[i]=sca.nextInt();
		}
       for(i=0;i<kazu-1;i++){
    	   for(j=kazu-1;j>0;j--){
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   }
	}
     for(i=0;i<kazu;i++){
    if(i!=kazu-1){	 
     System.out.print(hai[i]+" ");
     }else{
    	 System.out.println(hai[i]);
     }
     }
     System.out.println(cnt);

} int kazu kazu i i j j cnt=0 cnt 0 hz; hz Scanner sca = new Scanner(System.in); sca new Scanner(System.in) kazu=sca.nextInt() kazu sca.nextInt() sca.nextInt sca int hai[]=new int[kazu]; hai new int[kazu] kazu for(i=0;i<kazu;i++){
			hai[i]=sca.nextInt();
		} i=0; i=0 i 0 i<kazu i kazu i++ i++ i {
			hai[i]=sca.nextInt();
		} {
			hai[i]=sca.nextInt();
		} hai[i]=sca.nextInt() hai[i] hai i sca.nextInt() sca.nextInt sca for(i=0;i<kazu-1;i++){
    	   for(j=kazu-1;j>0;j--){
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   }
	} i=0; i=0 i 0 i<kazu-1 i kazu-1 kazu 1 i++ i++ i {
    	   for(j=kazu-1;j>0;j--){
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   }
	} {
    	   for(j=kazu-1;j>0;j--){
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   }
	} for(j=kazu-1;j>0;j--){
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   } j=kazu-1; j=kazu-1 j kazu-1 kazu 1 j>0 j 0 j-- j-- j {
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   } {
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   } if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   } hai[j]<hai[j-1] hai[j] hai j hai[j-1] hai j-1 j 1 {
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   } hz=hai[j] hz hai[j] hai j hai[j]=hai[j-1] hai[j] hai j hai[j-1] hai j-1 j 1 hai[j-1]=hz hai[j-1] hai j-1 j 1 hz cnt++ cnt for(i=0;i<kazu;i++){
    if(i!=kazu-1){	 
     System.out.print(hai[i]+" ");
     }else{
    	 System.out.println(hai[i]);
     }
     } i=0; i=0 i 0 i<kazu i kazu i++ i++ i {
    if(i!=kazu-1){	 
     System.out.print(hai[i]+" ");
     }else{
    	 System.out.println(hai[i]);
     }
     } {
    if(i!=kazu-1){	 
     System.out.print(hai[i]+" ");
     }else{
    	 System.out.println(hai[i]);
     }
     } if(i!=kazu-1){	 
     System.out.print(hai[i]+" ");
     }else{
    	 System.out.println(hai[i]);
     } i!=kazu-1 i kazu-1 kazu 1 {	 
     System.out.print(hai[i]+" ");
     } System.out.print(hai[i]+" ") System.out.print System.out System System.out hai[i]+" " hai[i] hai i " " {
    	 System.out.println(hai[i]);
     } System.out.println(hai[i]) System.out.println System.out System System.out hai[i] hai i System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int kazu,i,j,cnt=0,hz;
		Scanner sca = new Scanner(System.in);
		kazu=sca.nextInt();
		int hai[]=new int[kazu];
		for(i=0;i<kazu;i++){
			hai[i]=sca.nextInt();
		}
       for(i=0;i<kazu-1;i++){
    	   for(j=kazu-1;j>0;j--){
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   }
	}
     for(i=0;i<kazu;i++){
    if(i!=kazu-1){	 
     System.out.print(hai[i]+" ");
     }else{
    	 System.out.println(hai[i]);
     }
     }
     System.out.println(cnt);

}
} public class Main{

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int kazu,i,j,cnt=0,hz;
		Scanner sca = new Scanner(System.in);
		kazu=sca.nextInt();
		int hai[]=new int[kazu];
		for(i=0;i<kazu;i++){
			hai[i]=sca.nextInt();
		}
       for(i=0;i<kazu-1;i++){
    	   for(j=kazu-1;j>0;j--){
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   }
	}
     for(i=0;i<kazu;i++){
    if(i!=kazu-1){	 
     System.out.print(hai[i]+" ");
     }else{
    	 System.out.println(hai[i]);
     }
     }
     System.out.println(cnt);

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

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int kazu,i,j,cnt=0,hz;
		Scanner sca = new Scanner(System.in);
		kazu=sca.nextInt();
		int hai[]=new int[kazu];
		for(i=0;i<kazu;i++){
			hai[i]=sca.nextInt();
		}
       for(i=0;i<kazu-1;i++){
    	   for(j=kazu-1;j>0;j--){
    		   if(hai[j]<hai[j-1]){
    			   hz=hai[j];
    			   hai[j]=hai[j-1];
    			   hai[j-1]=hz;
    			   cnt++;
    		   }
    	   }
	}
     for(i=0;i<kazu;i++){
    if(i!=kazu-1){	 
     System.out.print(hai[i]+" ");
     }else{
    	 System.out.println(hai[i]);
     }
     }
     System.out.println(cnt);

}
}
