import java.util.Scanner;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();
    int[] array = new int[size];
    for (int i = 0; i < size; i++) {
      array[i] = sc.nextInt();
    }

    int count = 0;
    int tmp;
    for (int i = 0; i < size; i++) {
      for (int j = size - 1; j > i; j--) {
        if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        }
      }
    }

    for (int i = 0; i < size - 1; i++) {
      System.out.print(array[i] + " ");
    }
    System.out.println(array[size - 1]);
    System.out.println(count);
  }
}
 import java.util.Scanner; Scanner java.util class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();
    int[] array = new int[size];
    for (int i = 0; i < size; i++) {
      array[i] = sc.nextInt();
    }

    int count = 0;
    int tmp;
    for (int i = 0; i < size; i++) {
      for (int j = size - 1; j > i; j--) {
        if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        }
      }
    }

    for (int i = 0; i < size - 1; i++) {
      System.out.print(array[i] + " ");
    }
    System.out.println(array[size - 1]);
    System.out.println(count);
  }
} Main public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();
    int[] array = new int[size];
    for (int i = 0; i < size; i++) {
      array[i] = sc.nextInt();
    }

    int count = 0;
    int tmp;
    for (int i = 0; i < size; i++) {
      for (int j = size - 1; j > i; j--) {
        if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        }
      }
    }

    for (int i = 0; i < size - 1; i++) {
      System.out.print(array[i] + " ");
    }
    System.out.println(array[size - 1]);
    System.out.println(count);
  } main {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();
    int[] array = new int[size];
    for (int i = 0; i < size; i++) {
      array[i] = sc.nextInt();
    }

    int count = 0;
    int tmp;
    for (int i = 0; i < size; i++) {
      for (int j = size - 1; j > i; j--) {
        if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        }
      }
    }

    for (int i = 0; i < size - 1; i++) {
      System.out.print(array[i] + " ");
    }
    System.out.println(array[size - 1]);
    System.out.println(count);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int size = sc.nextInt(); size sc.nextInt() sc.nextInt sc int[] array = new int[size]; array new int[size] size for (int i = 0; i < size; i++) {
      array[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i < size i size i++ i++ i {
      array[i] = sc.nextInt();
    } {
      array[i] = sc.nextInt();
    } array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc int count = 0; count 0 int tmp; tmp for (int i = 0; i < size; i++) {
      for (int j = size - 1; j > i; j--) {
        if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        }
      }
    } int i = 0; int i = 0; i 0 i < size i size i++ i++ i {
      for (int j = size - 1; j > i; j--) {
        if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        }
      }
    } {
      for (int j = size - 1; j > i; j--) {
        if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        }
      }
    } for (int j = size - 1; j > i; j--) {
        if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        }
      } int j = size - 1; int j = size - 1; j size - 1 size 1 j > i j i j-- j-- j {
        if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        }
      } {
        if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        }
      } if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        } array[j] < array[j-1] array[j] array j array[j-1] array j-1 j 1 {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        } tmp = array[j-1] tmp array[j-1] array j-1 j 1 array[j-1] = array[j] array[j-1] array j-1 j 1 array[j] array j array[j] = tmp array[j] array j tmp count++ count for (int i = 0; i < size - 1; i++) {
      System.out.print(array[i] + " ");
    } int i = 0; int i = 0; i 0 i < size - 1 i size - 1 size 1 i++ i++ i {
      System.out.print(array[i] + " ");
    } {
      System.out.print(array[i] + " ");
    } System.out.print(array[i] + " ") System.out.print System.out System System.out array[i] + " " array[i] array i " " System.out.println(array[size - 1]) System.out.println System.out System System.out array[size - 1] array size - 1 size 1 System.out.println(count) System.out.println System.out System System.out count String... args args
import java.util.Scanner;

class Main {
  public static void main(String... args) {
    Scanner sc = new Scanner(System.in);
    int size = sc.nextInt();
    int[] array = new int[size];
    for (int i = 0; i < size; i++) {
      array[i] = sc.nextInt();
    }

    int count = 0;
    int tmp;
    for (int i = 0; i < size; i++) {
      for (int j = size - 1; j > i; j--) {
        if (array[j] < array[j-1]) {
          tmp = array[j-1];
          array[j-1] = array[j];
          array[j] = tmp;
          count++;
        }
      }
    }

    for (int i = 0; i < size - 1; i++) {
      System.out.print(array[i] + " ");
    }
    System.out.println(array[size - 1]);
    System.out.println(count);
  }
}

