import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		int count = 0;

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

			array[i] = sc.nextInt();

		}

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

			for(int j = n - 1; j >= i; j--) {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			}

		}

		printArray(array);
		System.out.println(count);

	}

	static void printArray(int[] array) {

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

		System.out.println(array[array.length - 1]);
	}

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

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		int count = 0;

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

			array[i] = sc.nextInt();

		}

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

			for(int j = n - 1; j >= i; j--) {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			}

		}

		printArray(array);
		System.out.println(count);

	}

	static void printArray(int[] array) {

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

		System.out.println(array[array.length - 1]);
	}

} Main public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		int count = 0;

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

			array[i] = sc.nextInt();

		}

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

			for(int j = n - 1; j >= i; j--) {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			}

		}

		printArray(array);
		System.out.println(count);

	} main {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		int count = 0;

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

			array[i] = sc.nextInt();

		}

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

			for(int j = n - 1; j >= i; j--) {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			}

		}

		printArray(array);
		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 int[] array = new int[n]; array new int[n] n int count = 0; count 0 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 for(int i = 1; i < n; i++) {

			for(int j = n - 1; j >= i; j--) {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			}

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

			for(int j = n - 1; j >= i; j--) {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			}

		} {

			for(int j = n - 1; j >= i; j--) {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			}

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

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			} int j = n - 1; int j = n - 1; j n - 1 n 1 j >= i j i j-- j-- j {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			} {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			} if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				} array[j - 1] > array[j] array[j - 1] array j - 1 j 1 array[j] array j {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				} int temp = array[j]; temp array[j] array j array[j] = array[j - 1] array[j] array j array[j - 1] array j - 1 j 1 array[j - 1] = temp array[j - 1] array j - 1 j 1 temp count++ count printArray(array) printArray array System.out.println(count) System.out.println System.out System System.out count String[] args args static void printArray(int[] array) {

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

		System.out.println(array[array.length - 1]);
	} printArray {

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

		System.out.println(array[array.length - 1]);
	} for(int i = 0; i < array.length - 1; i++) {
			System.out.print(array[i] + " ");
		} int i = 0; int i = 0; i 0 i < array.length - 1 i array.length - 1 array.length array array.length 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[array.length - 1]) System.out.println System.out System System.out array[array.length - 1] array array.length - 1 array.length array array.length 1 int[] array array public class Main {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		int count = 0;

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

			array[i] = sc.nextInt();

		}

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

			for(int j = n - 1; j >= i; j--) {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			}

		}

		printArray(array);
		System.out.println(count);

	}

	static void printArray(int[] array) {

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

		System.out.println(array[array.length - 1]);
	}

} public class Main {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		int count = 0;

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

			array[i] = sc.nextInt();

		}

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

			for(int j = n - 1; j >= i; j--) {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			}

		}

		printArray(array);
		System.out.println(count);

	}

	static void printArray(int[] array) {

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

		System.out.println(array[array.length - 1]);
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] array = new int[n];
		int count = 0;

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

			array[i] = sc.nextInt();

		}

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

			for(int j = n - 1; j >= i; j--) {

				if(array[j - 1] > array[j]) {

					int temp = array[j];
					array[j] = array[j - 1];
					array[j - 1] = temp;
					count++;
				}

			}

		}

		printArray(array);
		System.out.println(count);

	}

	static void printArray(int[] array) {

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

		System.out.println(array[array.length - 1]);
	}

}
