import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N[] = new int[100];
    int n = sc.nextInt();
    int m = 0;
    for (int i = 0; i < n; i++) N[i] = sc.nextInt();
    for (int i = 0; i < (n - 1); i++) {
      for (int j = (n - 1); j > i; j--) {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (i == 0) System.out.printf("%d", N[i]);
      else System.out.printf(" %d", N[i]);
    }
    System.out.printf("\n");
    System.out.println(m);
  }
}
 import java.util.Scanner; Scanner java.util public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N[] = new int[100];
    int n = sc.nextInt();
    int m = 0;
    for (int i = 0; i < n; i++) N[i] = sc.nextInt();
    for (int i = 0; i < (n - 1); i++) {
      for (int j = (n - 1); j > i; j--) {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (i == 0) System.out.printf("%d", N[i]);
      else System.out.printf(" %d", N[i]);
    }
    System.out.printf("\n");
    System.out.println(m);
  }
} Main public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N[] = new int[100];
    int n = sc.nextInt();
    int m = 0;
    for (int i = 0; i < n; i++) N[i] = sc.nextInt();
    for (int i = 0; i < (n - 1); i++) {
      for (int j = (n - 1); j > i; j--) {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (i == 0) System.out.printf("%d", N[i]);
      else System.out.printf(" %d", N[i]);
    }
    System.out.printf("\n");
    System.out.println(m);
  } main {
    Scanner sc = new Scanner(System.in);
    int N[] = new int[100];
    int n = sc.nextInt();
    int m = 0;
    for (int i = 0; i < n; i++) N[i] = sc.nextInt();
    for (int i = 0; i < (n - 1); i++) {
      for (int j = (n - 1); j > i; j--) {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (i == 0) System.out.printf("%d", N[i]);
      else System.out.printf(" %d", N[i]);
    }
    System.out.printf("\n");
    System.out.println(m);
  } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N[] = new int[100]; N new int[100] 100 int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int m = 0; m 0 for (int i = 0; i < n; i++) N[i] = sc.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i N[i] = sc.nextInt(); N[i] = sc.nextInt() N[i] N i sc.nextInt() sc.nextInt sc for (int i = 0; i < (n - 1); i++) {
      for (int j = (n - 1); j > i; j--) {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      }
    } int i = 0; int i = 0; i 0 i < (n - 1) i (n - 1) n 1 i++ i++ i {
      for (int j = (n - 1); j > i; j--) {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      }
    } {
      for (int j = (n - 1); j > i; j--) {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      }
    } for (int j = (n - 1); j > i; j--) {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      } int j = (n - 1); int j = (n - 1); j (n - 1) n 1 j > i j i j-- j-- j {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      } {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      } if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        } N[j-1] > N[j] N[j-1] N j-1 j 1 N[j] N j {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        } int t = N[j-1]; t N[j-1] N j-1 j 1 N[j-1] = N[j] N[j-1] N j-1 j 1 N[j] N j N[j] = t N[j] N j t m++ m for (int i = 0; i < n; i++) {
      if (i == 0) System.out.printf("%d", N[i]);
      else System.out.printf(" %d", N[i]);
    } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
      if (i == 0) System.out.printf("%d", N[i]);
      else System.out.printf(" %d", N[i]);
    } {
      if (i == 0) System.out.printf("%d", N[i]);
      else System.out.printf(" %d", N[i]);
    } if (i == 0) System.out.printf("%d", N[i]);
      else System.out.printf(" %d", N[i]); i == 0 i 0 System.out.printf("%d", N[i]) System.out.printf System.out System System.out "%d" N[i] N i System.out.printf(" %d", N[i]) System.out.printf System.out System System.out " %d" N[i] N i System.out.printf("\n") System.out.printf System.out System System.out "\n" System.out.println(m) System.out.println System.out System System.out m String[] args args public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N[] = new int[100];
    int n = sc.nextInt();
    int m = 0;
    for (int i = 0; i < n; i++) N[i] = sc.nextInt();
    for (int i = 0; i < (n - 1); i++) {
      for (int j = (n - 1); j > i; j--) {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (i == 0) System.out.printf("%d", N[i]);
      else System.out.printf(" %d", N[i]);
    }
    System.out.printf("\n");
    System.out.println(m);
  }
} public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N[] = new int[100];
    int n = sc.nextInt();
    int m = 0;
    for (int i = 0; i < n; i++) N[i] = sc.nextInt();
    for (int i = 0; i < (n - 1); i++) {
      for (int j = (n - 1); j > i; j--) {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (i == 0) System.out.printf("%d", N[i]);
      else System.out.printf(" %d", N[i]);
    }
    System.out.printf("\n");
    System.out.println(m);
  }
} Main
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N[] = new int[100];
    int n = sc.nextInt();
    int m = 0;
    for (int i = 0; i < n; i++) N[i] = sc.nextInt();
    for (int i = 0; i < (n - 1); i++) {
      for (int j = (n - 1); j > i; j--) {
        if (N[j-1] > N[j]) {
          int t = N[j-1];
          N[j-1] = N[j];
          N[j] = t;
          m++;
        }
      }
    }
    for (int i = 0; i < n; i++) {
      if (i == 0) System.out.printf("%d", N[i]);
      else System.out.printf(" %d", N[i]);
    }
    System.out.printf("\n");
    System.out.println(m);
  }
}

