import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		sc.nextLine();

		String[] datastr = sc.nextLine().split(" ");
		int[] a = new int[n];
		for (int i=0; i < n; i++) {
			a[i] = Integer.parseInt(datastr[i]);
		}

		int count = 0;

		for (int i=0; i < n; i++) {
			for (int j = n-1; i+1 <= j; j--) {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			}
		}

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

	}

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		sc.nextLine();

		String[] datastr = sc.nextLine().split(" ");
		int[] a = new int[n];
		for (int i=0; i < n; i++) {
			a[i] = Integer.parseInt(datastr[i]);
		}

		int count = 0;

		for (int i=0; i < n; i++) {
			for (int j = n-1; i+1 <= j; j--) {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			}
		}

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

	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		sc.nextLine();

		String[] datastr = sc.nextLine().split(" ");
		int[] a = new int[n];
		for (int i=0; i < n; i++) {
			a[i] = Integer.parseInt(datastr[i]);
		}

		int count = 0;

		for (int i=0; i < n; i++) {
			for (int j = n-1; i+1 <= j; j--) {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			}
		}

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

	} main {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		sc.nextLine();

		String[] datastr = sc.nextLine().split(" ");
		int[] a = new int[n];
		for (int i=0; i < n; i++) {
			a[i] = Integer.parseInt(datastr[i]);
		}

		int count = 0;

		for (int i=0; i < n; i++) {
			for (int j = n-1; i+1 <= j; j--) {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			}
		}

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

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc sc.nextLine() sc.nextLine sc String[] datastr = sc.nextLine().split(" "); datastr sc.nextLine().split(" ") sc.nextLine().split sc.nextLine() sc.nextLine sc " " int[] a = new int[n]; a new int[n] n for (int i=0; i < n; i++) {
			a[i] = Integer.parseInt(datastr[i]);
		} int i=0; int i=0; i 0 i < n i n i++ i++ i {
			a[i] = Integer.parseInt(datastr[i]);
		} {
			a[i] = Integer.parseInt(datastr[i]);
		} a[i] = Integer.parseInt(datastr[i]) a[i] a i Integer.parseInt(datastr[i]) Integer.parseInt Integer datastr[i] datastr i int count = 0; count 0 for (int i=0; i < n; i++) {
			for (int j = n-1; i+1 <= j; j--) {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			}
		} int i=0; int i=0; i 0 i < n i n i++ i++ i {
			for (int j = n-1; i+1 <= j; j--) {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			}
		} {
			for (int j = n-1; i+1 <= j; j--) {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			}
		} for (int j = n-1; i+1 <= j; j--) {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			} int j = n-1; int j = n-1; j n-1 n 1 i+1 <= j i+1 i 1 j j-- j-- j {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			} {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			} if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				} a[j-1] > a[j] a[j-1] a j-1 j 1 a[j] a j {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				} int temp = a[j]; temp a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1] = temp a[j-1] a j-1 j 1 temp count++ count for (int i=0; i < n-1; i++) {
			System.out.print(a[i] + " ");
		} int i=0; int i=0; i 0 i < n-1 i n-1 n 1 i++ i++ i {
			System.out.print(a[i] + " ");
		} {
			System.out.print(a[i] + " ");
		} System.out.print(a[i] + " ") System.out.print System.out System System.out a[i] + " " a[i] a i " " System.out.println(a[n-1]) System.out.println System.out System System.out a[n-1] a n-1 n 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		sc.nextLine();

		String[] datastr = sc.nextLine().split(" ");
		int[] a = new int[n];
		for (int i=0; i < n; i++) {
			a[i] = Integer.parseInt(datastr[i]);
		}

		int count = 0;

		for (int i=0; i < n; i++) {
			for (int j = n-1; i+1 <= j; j--) {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			}
		}

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

	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		sc.nextLine();

		String[] datastr = sc.nextLine().split(" ");
		int[] a = new int[n];
		for (int i=0; i < n; i++) {
			a[i] = Integer.parseInt(datastr[i]);
		}

		int count = 0;

		for (int i=0; i < n; i++) {
			for (int j = n-1; i+1 <= j; j--) {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			}
		}

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

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		sc.nextLine();

		String[] datastr = sc.nextLine().split(" ");
		int[] a = new int[n];
		for (int i=0; i < n; i++) {
			a[i] = Integer.parseInt(datastr[i]);
		}

		int count = 0;

		for (int i=0; i < n; i++) {
			for (int j = n-1; i+1 <= j; j--) {

				if (a[j-1] > a[j]) {
					int temp = a[j];
					a[j] = a[j-1];
					a[j-1] = temp;
					count++;
				}

			}
		}

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

	}

}