import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();
		boolean reverseElement = true;
		int count = 0;
		while (reverseElement) {
			reverseElement = false;
			for (int j = n - 1; j >= 1; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			}
		}
		for (int i = 0; i < n; i++)
			System.out.print(a[i] + (i != n - 1 ? " ":"\n"));
		System.out.println(count);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();
		boolean reverseElement = true;
		int count = 0;
		while (reverseElement) {
			reverseElement = false;
			for (int j = n - 1; j >= 1; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			}
		}
		for (int i = 0; i < n; i++)
			System.out.print(a[i] + (i != n - 1 ? " ":"\n"));
		System.out.println(count);
	}
	public static void main(String[] args) {
		new Main().run();
	}
} Main void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();
		boolean reverseElement = true;
		int count = 0;
		while (reverseElement) {
			reverseElement = false;
			for (int j = n - 1; j >= 1; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			}
		}
		for (int i = 0; i < n; i++)
			System.out.print(a[i] + (i != n - 1 ? " ":"\n"));
		System.out.println(count);
	} run {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();
		boolean reverseElement = true;
		int count = 0;
		while (reverseElement) {
			reverseElement = false;
			for (int j = n - 1; j >= 1; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			}
		}
		for (int i = 0; i < n; i++)
			System.out.print(a[i] + (i != n - 1 ? " ":"\n"));
		System.out.println(count);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; i++)
			a[i] = scan.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = scan.nextInt(); a[i] = scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan boolean reverseElement = true; reverseElement true int count = 0; count 0 while (reverseElement) {
			reverseElement = false;
			for (int j = n - 1; j >= 1; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			}
		} reverseElement {
			reverseElement = false;
			for (int j = n - 1; j >= 1; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			}
		} reverseElement = false reverseElement false for (int j = n - 1; j >= 1; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			} int j = n - 1; int j = n - 1; j n - 1 n 1 j >= 1 j 1 j-- j-- j {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			} {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			} if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				} a[j] < a[j - 1] a[j] a j a[j - 1] a j - 1 j 1 {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				} int tmp = a[j]; tmp a[j] a j a[j] = a[j - 1] a[j] a j a[j - 1] a j - 1 j 1 a[j - 1] = tmp a[j - 1] a j - 1 j 1 tmp reverseElement = true reverseElement true count++ count for (int i = 0; i < n; i++)
			System.out.print(a[i] + (i != n - 1 ? " ":"\n")); int i = 0; int i = 0; i 0 i < n i n i++ i++ i System.out.print(a[i] + (i != n - 1 ? " ":"\n")); System.out.print(a[i] + (i != n - 1 ? " ":"\n")) System.out.print System.out System System.out a[i] + (i != n - 1 ? " ":"\n") a[i] a i (i != n - 1 ? " ":"\n") i != n - 1 i n - 1 n 1 " " "\n" System.out.println(count) System.out.println System.out System System.out count 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 run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();
		boolean reverseElement = true;
		int count = 0;
		while (reverseElement) {
			reverseElement = false;
			for (int j = n - 1; j >= 1; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			}
		}
		for (int i = 0; i < n; i++)
			System.out.print(a[i] + (i != n - 1 ? " ":"\n"));
		System.out.println(count);
	}
	public static void main(String[] args) {
		new Main().run();
	}
} public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();
		boolean reverseElement = true;
		int count = 0;
		while (reverseElement) {
			reverseElement = false;
			for (int j = n - 1; j >= 1; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			}
		}
		for (int i = 0; i < n; i++)
			System.out.print(a[i] + (i != n - 1 ? " ":"\n"));
		System.out.println(count);
	}
	public static void main(String[] args) {
		new Main().run();
	}
} Main
import java.util.Scanner;

public class Main {
	void run() {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = scan.nextInt();
		boolean reverseElement = true;
		int count = 0;
		while (reverseElement) {
			reverseElement = false;
			for (int j = n - 1; j >= 1; j--) {
				if (a[j] < a[j - 1]) {
					int tmp = a[j];
					a[j] = a[j - 1];
					a[j - 1] = tmp;
					reverseElement = true;
					count++;
				}
			}
		}
		for (int i = 0; i < n; i++)
			System.out.print(a[i] + (i != n - 1 ? " ":"\n"));
		System.out.println(count);
	}
	public static void main(String[] args) {
		new Main().run();
	}
}

