import java.util.Scanner;

public class Main {

  static int bubbleSort(int[] a, int n) {
    int sw = 0;
    boolean flag = true;
    for (int i = 0; flag; i ++) {
      flag = false;
      for (int j = n - 1; j >= i + 1; j--) {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      }
    }
    return sw;
  }

  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = stdIn.nextInt();
    int sw = bubbleSort(a, n);
    for (int i = 0; i < n; i++) {
      System.out.print(a[i]);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    }
    System.out.println(sw);
  }
} import java.util.Scanner; Scanner java.util public class Main {

  static int bubbleSort(int[] a, int n) {
    int sw = 0;
    boolean flag = true;
    for (int i = 0; flag; i ++) {
      flag = false;
      for (int j = n - 1; j >= i + 1; j--) {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      }
    }
    return sw;
  }

  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = stdIn.nextInt();
    int sw = bubbleSort(a, n);
    for (int i = 0; i < n; i++) {
      System.out.print(a[i]);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    }
    System.out.println(sw);
  }
} Main static int bubbleSort(int[] a, int n) {
    int sw = 0;
    boolean flag = true;
    for (int i = 0; flag; i ++) {
      flag = false;
      for (int j = n - 1; j >= i + 1; j--) {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      }
    }
    return sw;
  } bubbleSort {
    int sw = 0;
    boolean flag = true;
    for (int i = 0; flag; i ++) {
      flag = false;
      for (int j = n - 1; j >= i + 1; j--) {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      }
    }
    return sw;
  } int sw = 0; sw 0 boolean flag = true; flag true for (int i = 0; flag; i ++) {
      flag = false;
      for (int j = n - 1; j >= i + 1; j--) {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      }
    } int i = 0; int i = 0; i 0 flag i ++ i ++ i {
      flag = false;
      for (int j = n - 1; j >= i + 1; j--) {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      }
    } {
      flag = false;
      for (int j = n - 1; j >= i + 1; j--) {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      }
    } flag = false flag false for (int j = n - 1; j >= i + 1; j--) {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      } int j = n - 1; int j = n - 1; j n - 1 n 1 j >= i + 1 j i + 1 i 1 j-- j-- j {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      } {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      } if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        } a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        } int 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 flag = true flag true sw++ sw return sw; sw int[] a a int n n public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = stdIn.nextInt();
    int sw = bubbleSort(a, n);
    for (int i = 0; i < n; i++) {
      System.out.print(a[i]);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    }
    System.out.println(sw);
  } main {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = stdIn.nextInt();
    int sw = bubbleSort(a, n);
    for (int i = 0; i < n; i++) {
      System.out.print(a[i]);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    }
    System.out.println(sw);
  } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++) a[i] = stdIn.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = stdIn.nextInt(); a[i] = stdIn.nextInt() a[i] a i stdIn.nextInt() stdIn.nextInt stdIn int sw = bubbleSort(a, n); sw bubbleSort(a, n) bubbleSort a n for (int i = 0; i < n; i++) {
      System.out.print(a[i]);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      System.out.print(a[i]);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    } {
      System.out.print(a[i]);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    } System.out.print(a[i]) System.out.print System.out System System.out a[i] a i if (i != n - 1) System.out.print(' ');
      else System.out.println(); i != n - 1 i n - 1 n 1 System.out.print(' ') System.out.print System.out System System.out ' ' System.out.println() System.out.println System.out System System.out System.out.println(sw) System.out.println System.out System System.out sw String[] args args public class Main {

  static int bubbleSort(int[] a, int n) {
    int sw = 0;
    boolean flag = true;
    for (int i = 0; flag; i ++) {
      flag = false;
      for (int j = n - 1; j >= i + 1; j--) {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      }
    }
    return sw;
  }

  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = stdIn.nextInt();
    int sw = bubbleSort(a, n);
    for (int i = 0; i < n; i++) {
      System.out.print(a[i]);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    }
    System.out.println(sw);
  }
} public class Main {

  static int bubbleSort(int[] a, int n) {
    int sw = 0;
    boolean flag = true;
    for (int i = 0; flag; i ++) {
      flag = false;
      for (int j = n - 1; j >= i + 1; j--) {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      }
    }
    return sw;
  }

  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = stdIn.nextInt();
    int sw = bubbleSort(a, n);
    for (int i = 0; i < n; i++) {
      System.out.print(a[i]);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    }
    System.out.println(sw);
  }
} Main
import java.util.Scanner;

public class Main {

  static int bubbleSort(int[] a, int n) {
    int sw = 0;
    boolean flag = true;
    for (int i = 0; flag; i ++) {
      flag = false;
      for (int j = n - 1; j >= i + 1; j--) {
        if (a[j] < a[j-1]) {
          int t = a[j];
          a[j] = a[j-1];
          a[j-1] = t;
          flag = true;
          sw++;
        }
      }
    }
    return sw;
  }

  public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int[] a = new int[n];
    for (int i = 0; i < n; i++) a[i] = stdIn.nextInt();
    int sw = bubbleSort(a, n);
    for (int i = 0; i < n; i++) {
      System.out.print(a[i]);
      if (i != n - 1) System.out.print(' ');
      else System.out.println();
    }
    System.out.println(sw);
  }
}