import java.util.Scanner;

// ALDS1_2_A
public class Main {
	void bubbleSort(int[] array, int n) {
		boolean flag = true;
		int tmp, count = 0;
		while (flag) {
			flag = false;
			for (int j = n - 1; j > 0; j--) {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.print(array[i]);
			if (i < n - 1) System.out.print(" ");;
		}
		System.out.println();
		System.out.println(count);
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		bubbleSort(array, n);
	}

	public static void main(String[] args) {
		new Main().run();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	void bubbleSort(int[] array, int n) {
		boolean flag = true;
		int tmp, count = 0;
		while (flag) {
			flag = false;
			for (int j = n - 1; j > 0; j--) {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.print(array[i]);
			if (i < n - 1) System.out.print(" ");;
		}
		System.out.println();
		System.out.println(count);
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		bubbleSort(array, n);
	}

	public static void main(String[] args) {
		new Main().run();
	}
} Main void bubbleSort(int[] array, int n) {
		boolean flag = true;
		int tmp, count = 0;
		while (flag) {
			flag = false;
			for (int j = n - 1; j > 0; j--) {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.print(array[i]);
			if (i < n - 1) System.out.print(" ");;
		}
		System.out.println();
		System.out.println(count);
	} bubbleSort {
		boolean flag = true;
		int tmp, count = 0;
		while (flag) {
			flag = false;
			for (int j = n - 1; j > 0; j--) {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.print(array[i]);
			if (i < n - 1) System.out.print(" ");;
		}
		System.out.println();
		System.out.println(count);
	} boolean flag = true; flag true int tmp tmp count = 0; count 0 while (flag) {
			flag = false;
			for (int j = n - 1; j > 0; j--) {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			}
		} flag {
			flag = false;
			for (int j = n - 1; j > 0; j--) {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			}
		} flag = false flag false for (int j = n - 1; j > 0; j--) {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			} int j = n - 1; int j = n - 1; j n - 1 n 1 j > 0 j 0 j-- j-- j {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			} {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			} if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				} array[j] < array[j-1] array[j] array j array[j-1] array j-1 j 1 {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				} tmp = array[j] tmp array[j] array j array[j] = array[j-1] array[j] array j array[j-1] array j-1 j 1 array[j-1] = tmp array[j-1] array j-1 j 1 tmp count++ count flag = true flag true for (int i = 0; i < n; i++) {
			System.out.print(array[i]);
			if (i < n - 1) System.out.print(" ");;
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			System.out.print(array[i]);
			if (i < n - 1) System.out.print(" ");;
		} {
			System.out.print(array[i]);
			if (i < n - 1) System.out.print(" ");;
		} System.out.print(array[i]) System.out.print System.out System System.out array[i] array i if (i < n - 1) System.out.print(" "); 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(count) System.out.println System.out System System.out count int[] array array int n n void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		bubbleSort(array, n);
	} run {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		bubbleSort(array, n);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] array = new int[n]; array new int[n] n for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			array[i] = sc.nextInt();
		} {
			array[i] = sc.nextInt();
		} array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc bubbleSort(array, n) bubbleSort array n public static void main(String[] args) {
		new Main().run();
	} main {
		new Main().run();
	} new Main().run() new Main().run new Main() String[] args args public class Main {
	void bubbleSort(int[] array, int n) {
		boolean flag = true;
		int tmp, count = 0;
		while (flag) {
			flag = false;
			for (int j = n - 1; j > 0; j--) {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.print(array[i]);
			if (i < n - 1) System.out.print(" ");;
		}
		System.out.println();
		System.out.println(count);
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		bubbleSort(array, n);
	}

	public static void main(String[] args) {
		new Main().run();
	}
} public class Main {
	void bubbleSort(int[] array, int n) {
		boolean flag = true;
		int tmp, count = 0;
		while (flag) {
			flag = false;
			for (int j = n - 1; j > 0; j--) {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.print(array[i]);
			if (i < n - 1) System.out.print(" ");;
		}
		System.out.println();
		System.out.println(count);
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		bubbleSort(array, n);
	}

	public static void main(String[] args) {
		new Main().run();
	}
} Main
import java.util.Scanner;

// ALDS1_2_A
public class Main {
	void bubbleSort(int[] array, int n) {
		boolean flag = true;
		int tmp, count = 0;
		while (flag) {
			flag = false;
			for (int j = n - 1; j > 0; j--) {
				if (array[j] < array[j-1]) {
					tmp = array[j]; array[j] = array[j-1]; array[j-1] = tmp;
					count++;
					flag = true;
				}
			}
		}
		for (int i = 0; i < n; i++) {
			System.out.print(array[i]);
			if (i < n - 1) System.out.print(" ");;
		}
		System.out.println();
		System.out.println(count);
	}
	
	void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		for (int i = 0; i < n; i++) {
			array[i] = sc.nextInt();
		}
		bubbleSort(array, n);
	}

	public static void main(String[] args) {
		new Main().run();
	}
}
