import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int n = Integer.parseInt( br.readLine() );
   String[] string=  br.readLine().split(" ");
   int [] Progression = new int[n];


   for(int i = 0; i < n ; i++){
       Progression[i] = Integer.parseInt(string[i] );
   }

   int tmp;
   int flag = 1;
   int count = 0;

    while(flag == 1){

    	flag = 0;
	  for(int j = n - 1; 0 < j; j--){

		  if( Progression[j] < Progression[j - 1] ){
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  }
	  }

    }

   for(int k = 0;k < n; k++){

	   System.out.print( Progression[k] );
	   if(k < n-1){
		   System.out.print(" ");
	   }else{
		   System.out.println();
	   }

   }

   System.out.println(count);


 }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int n = Integer.parseInt( br.readLine() );
   String[] string=  br.readLine().split(" ");
   int [] Progression = new int[n];


   for(int i = 0; i < n ; i++){
       Progression[i] = Integer.parseInt(string[i] );
   }

   int tmp;
   int flag = 1;
   int count = 0;

    while(flag == 1){

    	flag = 0;
	  for(int j = n - 1; 0 < j; j--){

		  if( Progression[j] < Progression[j - 1] ){
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  }
	  }

    }

   for(int k = 0;k < n; k++){

	   System.out.print( Progression[k] );
	   if(k < n-1){
		   System.out.print(" ");
	   }else{
		   System.out.println();
	   }

   }

   System.out.println(count);


 }
} Main public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int n = Integer.parseInt( br.readLine() );
   String[] string=  br.readLine().split(" ");
   int [] Progression = new int[n];


   for(int i = 0; i < n ; i++){
       Progression[i] = Integer.parseInt(string[i] );
   }

   int tmp;
   int flag = 1;
   int count = 0;

    while(flag == 1){

    	flag = 0;
	  for(int j = n - 1; 0 < j; j--){

		  if( Progression[j] < Progression[j - 1] ){
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  }
	  }

    }

   for(int k = 0;k < n; k++){

	   System.out.print( Progression[k] );
	   if(k < n-1){
		   System.out.print(" ");
	   }else{
		   System.out.println();
	   }

   }

   System.out.println(count);


 } main {
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int n = Integer.parseInt( br.readLine() );
   String[] string=  br.readLine().split(" ");
   int [] Progression = new int[n];


   for(int i = 0; i < n ; i++){
       Progression[i] = Integer.parseInt(string[i] );
   }

   int tmp;
   int flag = 1;
   int count = 0;

    while(flag == 1){

    	flag = 0;
	  for(int j = n - 1; 0 < j; j--){

		  if( Progression[j] < Progression[j - 1] ){
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  }
	  }

    }

   for(int k = 0;k < n; k++){

	   System.out.print( Progression[k] );
	   if(k < n-1){
		   System.out.print(" ");
	   }else{
		   System.out.println();
	   }

   }

   System.out.println(count);


 } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt( br.readLine() ); n Integer.parseInt( br.readLine() ) Integer.parseInt Integer br.readLine() br.readLine br String[] string=  br.readLine().split(" "); string br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int [] Progression = new int[n]; Progression new int[n] n for(int i = 0; i < n ; i++){
       Progression[i] = Integer.parseInt(string[i] );
   } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
       Progression[i] = Integer.parseInt(string[i] );
   } {
       Progression[i] = Integer.parseInt(string[i] );
   } Progression[i] = Integer.parseInt(string[i] ) Progression[i] Progression i Integer.parseInt(string[i] ) Integer.parseInt Integer string[i] string i int tmp; tmp int flag = 1; flag 1 int count = 0; count 0 while(flag == 1){

    	flag = 0;
	  for(int j = n - 1; 0 < j; j--){

		  if( Progression[j] < Progression[j - 1] ){
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  }
	  }

    } flag == 1 flag 1 {

    	flag = 0;
	  for(int j = n - 1; 0 < j; j--){

		  if( Progression[j] < Progression[j - 1] ){
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  }
	  }

    } flag = 0 flag 0 for(int j = n - 1; 0 < j; j--){

		  if( Progression[j] < Progression[j - 1] ){
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  }
	  } int j = n - 1; int j = n - 1; j n - 1 n 1 0 < j 0 j j-- j-- j {

		  if( Progression[j] < Progression[j - 1] ){
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  }
	  } {

		  if( Progression[j] < Progression[j - 1] ){
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  }
	  } if( Progression[j] < Progression[j - 1] ){
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  } Progression[j] < Progression[j - 1] Progression[j] Progression j Progression[j - 1] Progression j - 1 j 1 {
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  } tmp = Progression[j] tmp Progression[j] Progression j Progression[j] = Progression[j-1] Progression[j] Progression j Progression[j-1] Progression j-1 j 1 Progression[j-1] = tmp Progression[j-1] Progression j-1 j 1 tmp count++ count flag = 1 flag 1 for(int k = 0;k < n; k++){

	   System.out.print( Progression[k] );
	   if(k < n-1){
		   System.out.print(" ");
	   }else{
		   System.out.println();
	   }

   } int k = 0; int k = 0; k 0 k < n k n k++ k++ k {

	   System.out.print( Progression[k] );
	   if(k < n-1){
		   System.out.print(" ");
	   }else{
		   System.out.println();
	   }

   } {

	   System.out.print( Progression[k] );
	   if(k < n-1){
		   System.out.print(" ");
	   }else{
		   System.out.println();
	   }

   } System.out.print( Progression[k] ) System.out.print System.out System System.out Progression[k] Progression k if(k < n-1){
		   System.out.print(" ");
	   }else{
		   System.out.println();
	   } k < n-1 k n-1 n 1 {
		   System.out.print(" ");
	   } System.out.print(" ") System.out.print System.out System System.out " " {
		   System.out.println();
	   } 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 args[] args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main{
  public static void main(String args[]) throws IOException{
   BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

   int n = Integer.parseInt( br.readLine() );
   String[] string=  br.readLine().split(" ");
   int [] Progression = new int[n];


   for(int i = 0; i < n ; i++){
       Progression[i] = Integer.parseInt(string[i] );
   }

   int tmp;
   int flag = 1;
   int count = 0;

    while(flag == 1){

    	flag = 0;
	  for(int j = n - 1; 0 < j; j--){

		  if( Progression[j] < Progression[j - 1] ){
			  tmp = Progression[j];
			  Progression[j] = Progression[j-1];
			  Progression[j-1] = tmp;
			  count++;
			  flag = 1;
		  }
	  }

    }

   for(int k = 0;k < n; k++){

	   System.out.print( Progression[k] );
	   if(k < n-1){
		   System.out.print(" ");
	   }else{
		   System.out.println();
	   }

   }

   System.out.println(count);


 }
}