import java.util.*;

public class Main {
   public static void main(String [] args) {
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.nextLine());
      int[] arr = new int[n];
      String[] input = sc.nextLine().split(" ");
      for(int i = 0; i < n; i ++) {
         arr[i] = Integer.parseInt(input[i]);
      }
      
      int counter = 0;
      boolean comp = false;
      while(!comp) {
         comp = true;
         for(int i = n-1; i >= 1; i --) {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         }
      }
      
      for(int i = 0; i < n; i ++) {
         System.out.print(arr[i]);
         if(i != n-1) {
            System.out.print(" ");
         }
      }
      System.out.println("\n" + counter);
   }
} import java.util.*; util.* java public class Main {
   public static void main(String [] args) {
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.nextLine());
      int[] arr = new int[n];
      String[] input = sc.nextLine().split(" ");
      for(int i = 0; i < n; i ++) {
         arr[i] = Integer.parseInt(input[i]);
      }
      
      int counter = 0;
      boolean comp = false;
      while(!comp) {
         comp = true;
         for(int i = n-1; i >= 1; i --) {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         }
      }
      
      for(int i = 0; i < n; i ++) {
         System.out.print(arr[i]);
         if(i != n-1) {
            System.out.print(" ");
         }
      }
      System.out.println("\n" + counter);
   }
} Main public static void main(String [] args) {
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.nextLine());
      int[] arr = new int[n];
      String[] input = sc.nextLine().split(" ");
      for(int i = 0; i < n; i ++) {
         arr[i] = Integer.parseInt(input[i]);
      }
      
      int counter = 0;
      boolean comp = false;
      while(!comp) {
         comp = true;
         for(int i = n-1; i >= 1; i --) {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         }
      }
      
      for(int i = 0; i < n; i ++) {
         System.out.print(arr[i]);
         if(i != n-1) {
            System.out.print(" ");
         }
      }
      System.out.println("\n" + counter);
   } main {
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.nextLine());
      int[] arr = new int[n];
      String[] input = sc.nextLine().split(" ");
      for(int i = 0; i < n; i ++) {
         arr[i] = Integer.parseInt(input[i]);
      }
      
      int counter = 0;
      boolean comp = false;
      while(!comp) {
         comp = true;
         for(int i = n-1; i >= 1; i --) {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         }
      }
      
      for(int i = 0; i < n; i ++) {
         System.out.print(arr[i]);
         if(i != n-1) {
            System.out.print(" ");
         }
      }
      System.out.println("\n" + counter);
   } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = Integer.parseInt(sc.nextLine()); n Integer.parseInt(sc.nextLine()) Integer.parseInt Integer sc.nextLine() sc.nextLine sc int[] arr = new int[n]; arr new int[n] n String[] input = sc.nextLine().split(" "); input sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " for(int i = 0; i < n; i ++) {
         arr[i] = Integer.parseInt(input[i]);
      } int i = 0; int i = 0; i 0 i < n i n i ++ i ++ i {
         arr[i] = Integer.parseInt(input[i]);
      } {
         arr[i] = Integer.parseInt(input[i]);
      } arr[i] = Integer.parseInt(input[i]) arr[i] arr i Integer.parseInt(input[i]) Integer.parseInt Integer input[i] input i int counter = 0; counter 0 boolean comp = false; comp false while(!comp) {
         comp = true;
         for(int i = n-1; i >= 1; i --) {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         }
      } !comp comp {
         comp = true;
         for(int i = n-1; i >= 1; i --) {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         }
      } comp = true comp true for(int i = n-1; i >= 1; i --) {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         } int i = n-1; int i = n-1; i n-1 n 1 i >= 1 i 1 i -- i -- i {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         } {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         } if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            } arr[i-1] > arr[i] arr[i-1] arr i-1 i 1 arr[i] arr i {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            } int temp = arr[i]; temp arr[i] arr i arr[i] = arr[i-1] arr[i] arr i arr[i-1] arr i-1 i 1 arr[i-1] = temp arr[i-1] arr i-1 i 1 temp comp = false comp false counter ++ counter for(int i = 0; i < n; i ++) {
         System.out.print(arr[i]);
         if(i != n-1) {
            System.out.print(" ");
         }
      } int i = 0; int i = 0; i 0 i < n i n i ++ i ++ i {
         System.out.print(arr[i]);
         if(i != n-1) {
            System.out.print(" ");
         }
      } {
         System.out.print(arr[i]);
         if(i != n-1) {
            System.out.print(" ");
         }
      } System.out.print(arr[i]) System.out.print System.out System System.out arr[i] arr i if(i != n-1) {
            System.out.print(" ");
         } i != n-1 i n-1 n 1 {
            System.out.print(" ");
         } System.out.print(" ") System.out.print System.out System System.out " " System.out.println("\n" + counter) System.out.println System.out System System.out "\n" + counter "\n" counter String [] args args public class Main {
   public static void main(String [] args) {
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.nextLine());
      int[] arr = new int[n];
      String[] input = sc.nextLine().split(" ");
      for(int i = 0; i < n; i ++) {
         arr[i] = Integer.parseInt(input[i]);
      }
      
      int counter = 0;
      boolean comp = false;
      while(!comp) {
         comp = true;
         for(int i = n-1; i >= 1; i --) {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         }
      }
      
      for(int i = 0; i < n; i ++) {
         System.out.print(arr[i]);
         if(i != n-1) {
            System.out.print(" ");
         }
      }
      System.out.println("\n" + counter);
   }
} public class Main {
   public static void main(String [] args) {
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.nextLine());
      int[] arr = new int[n];
      String[] input = sc.nextLine().split(" ");
      for(int i = 0; i < n; i ++) {
         arr[i] = Integer.parseInt(input[i]);
      }
      
      int counter = 0;
      boolean comp = false;
      while(!comp) {
         comp = true;
         for(int i = n-1; i >= 1; i --) {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         }
      }
      
      for(int i = 0; i < n; i ++) {
         System.out.print(arr[i]);
         if(i != n-1) {
            System.out.print(" ");
         }
      }
      System.out.println("\n" + counter);
   }
} Main
import java.util.*;

public class Main {
   public static void main(String [] args) {
      Scanner sc = new Scanner(System.in);
      int n = Integer.parseInt(sc.nextLine());
      int[] arr = new int[n];
      String[] input = sc.nextLine().split(" ");
      for(int i = 0; i < n; i ++) {
         arr[i] = Integer.parseInt(input[i]);
      }
      
      int counter = 0;
      boolean comp = false;
      while(!comp) {
         comp = true;
         for(int i = n-1; i >= 1; i --) {
            if(arr[i-1] > arr[i]) {
               int temp = arr[i];
               arr[i] = arr[i-1];
               arr[i-1] = temp;
               comp = false;
               counter ++;
            }
         }
      }
      
      for(int i = 0; i < n; i ++) {
         System.out.print(arr[i]);
         if(i != n-1) {
            System.out.print(" ");
         }
      }
      System.out.println("\n" + counter);
   }
}
