import java.io.*;

public class Main {
  public static void main(String[] args) {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int count = Integer.parseInt(in.readLine());
      String[] arrStr = in.readLine().split(" ");
      int[] arrInt = new int[count];
      for(int i=0; i<count; i++) { arrInt[i] = Integer.parseInt(arrStr[i]); }
      int flag = 1;
      int cntResult = 0;
      while(flag==1) {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      }
      StringBuilder sb = new StringBuilder();
      for( int i : arrInt ) { sb.append(i).append(" "); }
      System.out.println(sb.toString().trim());
      System.out.println(cntResult);
    } catch (IOException e) {
    }
  }
} import java.io.*; io.* java public class Main {
  public static void main(String[] args) {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int count = Integer.parseInt(in.readLine());
      String[] arrStr = in.readLine().split(" ");
      int[] arrInt = new int[count];
      for(int i=0; i<count; i++) { arrInt[i] = Integer.parseInt(arrStr[i]); }
      int flag = 1;
      int cntResult = 0;
      while(flag==1) {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      }
      StringBuilder sb = new StringBuilder();
      for( int i : arrInt ) { sb.append(i).append(" "); }
      System.out.println(sb.toString().trim());
      System.out.println(cntResult);
    } catch (IOException e) {
    }
  }
} Main public static void main(String[] args) {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int count = Integer.parseInt(in.readLine());
      String[] arrStr = in.readLine().split(" ");
      int[] arrInt = new int[count];
      for(int i=0; i<count; i++) { arrInt[i] = Integer.parseInt(arrStr[i]); }
      int flag = 1;
      int cntResult = 0;
      while(flag==1) {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      }
      StringBuilder sb = new StringBuilder();
      for( int i : arrInt ) { sb.append(i).append(" "); }
      System.out.println(sb.toString().trim());
      System.out.println(cntResult);
    } catch (IOException e) {
    }
  } main {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int count = Integer.parseInt(in.readLine());
      String[] arrStr = in.readLine().split(" ");
      int[] arrInt = new int[count];
      for(int i=0; i<count; i++) { arrInt[i] = Integer.parseInt(arrStr[i]); }
      int flag = 1;
      int cntResult = 0;
      while(flag==1) {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      }
      StringBuilder sb = new StringBuilder();
      for( int i : arrInt ) { sb.append(i).append(" "); }
      System.out.println(sb.toString().trim());
      System.out.println(cntResult);
    } catch (IOException e) {
    }
  } try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int count = Integer.parseInt(in.readLine());
      String[] arrStr = in.readLine().split(" ");
      int[] arrInt = new int[count];
      for(int i=0; i<count; i++) { arrInt[i] = Integer.parseInt(arrStr[i]); }
      int flag = 1;
      int cntResult = 0;
      while(flag==1) {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      }
      StringBuilder sb = new StringBuilder();
      for( int i : arrInt ) { sb.append(i).append(" "); }
      System.out.println(sb.toString().trim());
      System.out.println(cntResult);
    } catch (IOException e) {
    } catch (IOException e) {
    } IOException e {
    } {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int count = Integer.parseInt(in.readLine());
      String[] arrStr = in.readLine().split(" ");
      int[] arrInt = new int[count];
      for(int i=0; i<count; i++) { arrInt[i] = Integer.parseInt(arrStr[i]); }
      int flag = 1;
      int cntResult = 0;
      while(flag==1) {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      }
      StringBuilder sb = new StringBuilder();
      for( int i : arrInt ) { sb.append(i).append(" "); }
      System.out.println(sb.toString().trim());
      System.out.println(cntResult);
    } BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) int count = Integer.parseInt(in.readLine()); count Integer.parseInt(in.readLine()) Integer.parseInt Integer in.readLine() in.readLine in String[] arrStr = in.readLine().split(" "); arrStr in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " int[] arrInt = new int[count]; arrInt new int[count] count for(int i=0; i<count; i++) { arrInt[i] = Integer.parseInt(arrStr[i]); } int i=0; int i=0; i 0 i<count i count i++ i++ i { arrInt[i] = Integer.parseInt(arrStr[i]); } { arrInt[i] = Integer.parseInt(arrStr[i]); } arrInt[i] = Integer.parseInt(arrStr[i]) arrInt[i] arrInt i Integer.parseInt(arrStr[i]) Integer.parseInt Integer arrStr[i] arrStr i int flag = 1; flag 1 int cntResult = 0; cntResult 0 while(flag==1) {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      } flag==1 flag 1 {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      } flag = 0 flag 0 for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        } int j = count-1; int j = count-1; j count-1 count 1 j > 0 j 0 j-- j-- j {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        } {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        } if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          } arrInt[j] < arrInt[j-1] arrInt[j] arrInt j arrInt[j-1] arrInt j-1 j 1 {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          } int tmp = arrInt[j]; tmp arrInt[j] arrInt j arrInt[j] = arrInt[j-1] arrInt[j] arrInt j arrInt[j-1] arrInt j-1 j 1 arrInt[j-1] = tmp arrInt[j-1] arrInt j-1 j 1 tmp flag = 1 flag 1 cntResult++ cntResult StringBuilder sb = new StringBuilder(); sb new StringBuilder() for( int i : arrInt ) { sb.append(i).append(" "); } int i arrInt { sb.append(i).append(" "); } { sb.append(i).append(" "); } sb.append(i).append(" ") sb.append(i).append sb.append(i) sb.append sb i " " System.out.println(sb.toString().trim()) System.out.println System.out System System.out sb.toString().trim() sb.toString().trim sb.toString() sb.toString sb System.out.println(cntResult) System.out.println System.out System System.out cntResult String[] args args public class Main {
  public static void main(String[] args) {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int count = Integer.parseInt(in.readLine());
      String[] arrStr = in.readLine().split(" ");
      int[] arrInt = new int[count];
      for(int i=0; i<count; i++) { arrInt[i] = Integer.parseInt(arrStr[i]); }
      int flag = 1;
      int cntResult = 0;
      while(flag==1) {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      }
      StringBuilder sb = new StringBuilder();
      for( int i : arrInt ) { sb.append(i).append(" "); }
      System.out.println(sb.toString().trim());
      System.out.println(cntResult);
    } catch (IOException e) {
    }
  }
} public class Main {
  public static void main(String[] args) {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int count = Integer.parseInt(in.readLine());
      String[] arrStr = in.readLine().split(" ");
      int[] arrInt = new int[count];
      for(int i=0; i<count; i++) { arrInt[i] = Integer.parseInt(arrStr[i]); }
      int flag = 1;
      int cntResult = 0;
      while(flag==1) {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      }
      StringBuilder sb = new StringBuilder();
      for( int i : arrInt ) { sb.append(i).append(" "); }
      System.out.println(sb.toString().trim());
      System.out.println(cntResult);
    } catch (IOException e) {
    }
  }
} Main
import java.io.*;

public class Main {
  public static void main(String[] args) {
    try {
      BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
      int count = Integer.parseInt(in.readLine());
      String[] arrStr = in.readLine().split(" ");
      int[] arrInt = new int[count];
      for(int i=0; i<count; i++) { arrInt[i] = Integer.parseInt(arrStr[i]); }
      int flag = 1;
      int cntResult = 0;
      while(flag==1) {
        flag = 0;
        for( int j = count-1; j > 0; j-- ) {
          if(arrInt[j] < arrInt[j-1]) {
            int tmp = arrInt[j];
            arrInt[j] = arrInt[j-1];
            arrInt[j-1] = tmp;
            flag = 1;
            cntResult++;
          }
        }
      }
      StringBuilder sb = new StringBuilder();
      for( int i : arrInt ) { sb.append(i).append(" "); }
      System.out.println(sb.toString().trim());
      System.out.println(cntResult);
    } catch (IOException e) {
    }
  }
}