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

public class Main {

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

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++)
        seq[i] = Integer.parseInt(line[i]);

      count = bubbleSort(seq, n);

      dispIntArray(seq);
      System.out.println(count);
    }
  }

  static int bubbleSort(int[] a, int n) {
    int count=0;

    for(int i=0,f=1,t; i<n || f==1; i++ ) {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      }
    }

    return count;
  }

  public static void dispIntArray(int a[]) {
    StringBuilder s = new StringBuilder();

    for (int i : a) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

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

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++)
        seq[i] = Integer.parseInt(line[i]);

      count = bubbleSort(seq, n);

      dispIntArray(seq);
      System.out.println(count);
    }
  }

  static int bubbleSort(int[] a, int n) {
    int count=0;

    for(int i=0,f=1,t; i<n || f==1; i++ ) {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      }
    }

    return count;
  }

  public static void dispIntArray(int a[]) {
    StringBuilder s = new StringBuilder();

    for (int i : a) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

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

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++)
        seq[i] = Integer.parseInt(line[i]);

      count = bubbleSort(seq, n);

      dispIntArray(seq);
      System.out.println(count);
    }
  } main {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++)
        seq[i] = Integer.parseInt(line[i]);

      count = bubbleSort(seq, n);

      dispIntArray(seq);
      System.out.println(count);
    }
  } try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++)
        seq[i] = Integer.parseInt(line[i]);

      count = bubbleSort(seq, n);

      dispIntArray(seq);
      System.out.println(count);
    } {

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++)
        seq[i] = Integer.parseInt(line[i]);

      count = bubbleSort(seq, n);

      dispIntArray(seq);
      System.out.println(count);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) int count=0; count 0 int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] seq = new int[n]; seq new int[n] n String[] line = br.readLine().split(" "); line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int i=0; i < n; i++)
        seq[i] = Integer.parseInt(line[i]); int i=0; int i=0; i 0 i < n i n i++ i++ i seq[i] = Integer.parseInt(line[i]); seq[i] = Integer.parseInt(line[i]) seq[i] seq i Integer.parseInt(line[i]) Integer.parseInt Integer line[i] line i count = bubbleSort(seq, n) count bubbleSort(seq, n) bubbleSort seq n dispIntArray(seq) dispIntArray seq System.out.println(count) System.out.println System.out System System.out count String[] args args static int bubbleSort(int[] a, int n) {
    int count=0;

    for(int i=0,f=1,t; i<n || f==1; i++ ) {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      }
    }

    return count;
  } bubbleSort {
    int count=0;

    for(int i=0,f=1,t; i<n || f==1; i++ ) {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      }
    }

    return count;
  } int count=0; count 0 for(int i=0,f=1,t; i<n || f==1; i++ ) {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      }
    } int i=0,f=1,t; int i=0 i 0 f=1 f 1 t; t i<n || f==1 i<n i n f==1 f 1 i++ i++ i {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      }
    } {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      }
    } f=0 f 0 for(int j=n-1; j>0; j-- ) {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      } int j=n-1; int j=n-1; j n-1 n 1 j>0 j 0 j-- j-- j {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      } {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      } if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        } a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        } t = a[j] t a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1] = t a[j-1] a j-1 j 1 t count++ count f=1 f 1 return count; count int[] a a int n n public static void dispIntArray(int a[]) {
    StringBuilder s = new StringBuilder();

    for (int i : a) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  } dispIntArray {
    StringBuilder s = new StringBuilder();

    for (int i : a) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  } StringBuilder s = new StringBuilder(); s new StringBuilder() for (int i : a) { s.append(i).append(" "); } int i a { s.append(i).append(" "); } { s.append(i).append(" "); } s.append(i).append(" ") s.append(i).append s.append(i) s.append s i " " s.setLength(s.length()-1) s.setLength s s.length()-1 s.length() s.length s 1 System.out.println(s) System.out.println System.out System System.out s int a[] a public class Main {

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

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++)
        seq[i] = Integer.parseInt(line[i]);

      count = bubbleSort(seq, n);

      dispIntArray(seq);
      System.out.println(count);
    }
  }

  static int bubbleSort(int[] a, int n) {
    int count=0;

    for(int i=0,f=1,t; i<n || f==1; i++ ) {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      }
    }

    return count;
  }

  public static void dispIntArray(int a[]) {
    StringBuilder s = new StringBuilder();

    for (int i : a) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
} public class Main {

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

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++)
        seq[i] = Integer.parseInt(line[i]);

      count = bubbleSort(seq, n);

      dispIntArray(seq);
      System.out.println(count);
    }
  }

  static int bubbleSort(int[] a, int n) {
    int count=0;

    for(int i=0,f=1,t; i<n || f==1; i++ ) {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      }
    }

    return count;
  }

  public static void dispIntArray(int a[]) {
    StringBuilder s = new StringBuilder();

    for (int i : a) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

      int count=0;
      int n = Integer.parseInt(br.readLine());
      int[] seq = new int[n];
      String[] line = br.readLine().split(" ");
      for (int i=0; i < n; i++)
        seq[i] = Integer.parseInt(line[i]);

      count = bubbleSort(seq, n);

      dispIntArray(seq);
      System.out.println(count);
    }
  }

  static int bubbleSort(int[] a, int n) {
    int count=0;

    for(int i=0,f=1,t; i<n || f==1; i++ ) {
      f=0;
      for(int j=n-1; j>0; j-- ) {
        if( a[j] < a[j-1]) {
          t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          count++;
          f=1;
        }
      }
    }

    return count;
  }

  public static void dispIntArray(int a[]) {
    StringBuilder s = new StringBuilder();

    for (int i : a) { s.append(i).append(" "); }
    s.setLength(s.length()-1);

    System.out.println(s);
  }
}
