import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    List<Integer> numbers = new ArrayList<Integer>();
    for (int i = 0; i < N; ++i) {
      numbers.add(scanner.nextInt());
    }

    int temp, count = 0;
    for (int i = 0; i + 1 < N; ++i) {
      for (int j = 0; j + 1 < N - i; ++j) {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      }
    }

    if (N == 0) count = 1;

    for (int i = 0; i < N - 1; ++i) System.out.print(numbers.get(i) + " ");
    System.out.println(numbers.get(N - 1) + "\n" + count);
  }
} import java.util.Scanner; Scanner java.util import java.util.List; List java.util import java.util.ArrayList; ArrayList java.util public class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    List<Integer> numbers = new ArrayList<Integer>();
    for (int i = 0; i < N; ++i) {
      numbers.add(scanner.nextInt());
    }

    int temp, count = 0;
    for (int i = 0; i + 1 < N; ++i) {
      for (int j = 0; j + 1 < N - i; ++j) {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      }
    }

    if (N == 0) count = 1;

    for (int i = 0; i < N - 1; ++i) System.out.print(numbers.get(i) + " ");
    System.out.println(numbers.get(N - 1) + "\n" + count);
  }
} Main public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    List<Integer> numbers = new ArrayList<Integer>();
    for (int i = 0; i < N; ++i) {
      numbers.add(scanner.nextInt());
    }

    int temp, count = 0;
    for (int i = 0; i + 1 < N; ++i) {
      for (int j = 0; j + 1 < N - i; ++j) {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      }
    }

    if (N == 0) count = 1;

    for (int i = 0; i < N - 1; ++i) System.out.print(numbers.get(i) + " ");
    System.out.println(numbers.get(N - 1) + "\n" + count);
  } main {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    List<Integer> numbers = new ArrayList<Integer>();
    for (int i = 0; i < N; ++i) {
      numbers.add(scanner.nextInt());
    }

    int temp, count = 0;
    for (int i = 0; i + 1 < N; ++i) {
      for (int j = 0; j + 1 < N - i; ++j) {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      }
    }

    if (N == 0) count = 1;

    for (int i = 0; i < N - 1; ++i) System.out.print(numbers.get(i) + " ");
    System.out.println(numbers.get(N - 1) + "\n" + count);
  } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner List<Integer> numbers = new ArrayList<Integer>(); numbers new ArrayList<Integer>() for (int i = 0; i < N; ++i) {
      numbers.add(scanner.nextInt());
    } int i = 0; int i = 0; i 0 i < N i N ++i ++i i {
      numbers.add(scanner.nextInt());
    } {
      numbers.add(scanner.nextInt());
    } numbers.add(scanner.nextInt()) numbers.add numbers scanner.nextInt() scanner.nextInt scanner int temp temp count = 0; count 0 for (int i = 0; i + 1 < N; ++i) {
      for (int j = 0; j + 1 < N - i; ++j) {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      }
    } int i = 0; int i = 0; i 0 i + 1 < N i + 1 i 1 N ++i ++i i {
      for (int j = 0; j + 1 < N - i; ++j) {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      }
    } {
      for (int j = 0; j + 1 < N - i; ++j) {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      }
    } for (int j = 0; j + 1 < N - i; ++j) {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      } int j = 0; int j = 0; j 0 j + 1 < N - i j + 1 j 1 N - i N i ++j ++j j {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      } {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      } if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        } numbers.get(j) > numbers.get(j + 1) numbers.get(j) numbers.get numbers j numbers.get(j + 1) numbers.get numbers j + 1 j 1 {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        } temp = numbers.get(j + 1) temp numbers.get(j + 1) numbers.get numbers j + 1 j 1 numbers.set(j + 1, numbers.get(j)) numbers.set numbers j + 1 j 1 numbers.get(j) numbers.get numbers j numbers.set(j, temp) numbers.set numbers j temp ++count count if (N == 0) count = 1; N == 0 N 0 count = 1 count 1 for (int i = 0; i < N - 1; ++i) System.out.print(numbers.get(i) + " "); int i = 0; int i = 0; i 0 i < N - 1 i N - 1 N 1 ++i ++i i System.out.print(numbers.get(i) + " "); System.out.print(numbers.get(i) + " ") System.out.print System.out System System.out numbers.get(i) + " " numbers.get(i) numbers.get numbers i " " System.out.println(numbers.get(N - 1) + "\n" + count) System.out.println System.out System System.out numbers.get(N - 1) + "\n" + count numbers.get(N - 1) + "\n" + count numbers.get(N - 1) numbers.get numbers N - 1 N 1 "\n" count String[] args args public class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    List<Integer> numbers = new ArrayList<Integer>();
    for (int i = 0; i < N; ++i) {
      numbers.add(scanner.nextInt());
    }

    int temp, count = 0;
    for (int i = 0; i + 1 < N; ++i) {
      for (int j = 0; j + 1 < N - i; ++j) {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      }
    }

    if (N == 0) count = 1;

    for (int i = 0; i < N - 1; ++i) System.out.print(numbers.get(i) + " ");
    System.out.println(numbers.get(N - 1) + "\n" + count);
  }
} public class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    List<Integer> numbers = new ArrayList<Integer>();
    for (int i = 0; i < N; ++i) {
      numbers.add(scanner.nextInt());
    }

    int temp, count = 0;
    for (int i = 0; i + 1 < N; ++i) {
      for (int j = 0; j + 1 < N - i; ++j) {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      }
    }

    if (N == 0) count = 1;

    for (int i = 0; i < N - 1; ++i) System.out.print(numbers.get(i) + " ");
    System.out.println(numbers.get(N - 1) + "\n" + count);
  }
} Main
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;

public class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    List<Integer> numbers = new ArrayList<Integer>();
    for (int i = 0; i < N; ++i) {
      numbers.add(scanner.nextInt());
    }

    int temp, count = 0;
    for (int i = 0; i + 1 < N; ++i) {
      for (int j = 0; j + 1 < N - i; ++j) {
        if (numbers.get(j) > numbers.get(j + 1)) {
          temp = numbers.get(j + 1);
          numbers.set(j + 1, numbers.get(j));
          numbers.set(j, temp);
          ++count;
        }
      }
    }

    if (N == 0) count = 1;

    for (int i = 0; i < N - 1; ++i) System.out.print(numbers.get(i) + " ");
    System.out.println(numbers.get(N - 1) + "\n" + count);
  }
}
