import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	StringBuilder out;

	void run() {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		}

		int cnt = 0;
		for (int i = N - 1; i >= 0; i--) {
			for (int j = 0; j < i; j++) {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			}
		}
		for (int i = 0; i < A.length; i++) {
			System.out.print((i == 0 ? "" : " ") + A[i]);
		}
		System.out.println("\n" + cnt);
	}

	public static void main(String[] args) {
		new Main().run();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	Scanner sc = new Scanner(System.in);
	StringBuilder out;

	void run() {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		}

		int cnt = 0;
		for (int i = N - 1; i >= 0; i--) {
			for (int j = 0; j < i; j++) {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			}
		}
		for (int i = 0; i < A.length; i++) {
			System.out.print((i == 0 ? "" : " ") + A[i]);
		}
		System.out.println("\n" + cnt);
	}

	public static void main(String[] args) {
		new Main().run();
	}
} Main Scanner sc = new Scanner(System.in); sc new Scanner(System.in) StringBuilder out; out void run() {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		}

		int cnt = 0;
		for (int i = N - 1; i >= 0; i--) {
			for (int j = 0; j < i; j++) {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			}
		}
		for (int i = 0; i < A.length; i++) {
			System.out.print((i == 0 ? "" : " ") + A[i]);
		}
		System.out.println("\n" + cnt);
	} run {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		}

		int cnt = 0;
		for (int i = N - 1; i >= 0; i--) {
			for (int j = 0; j < i; j++) {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			}
		}
		for (int i = 0; i < A.length; i++) {
			System.out.print((i == 0 ? "" : " ") + A[i]);
		}
		System.out.println("\n" + cnt);
	} int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] A = new int[N]; A new int[N] N for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < A.length i A.length A A.length i++ i++ i {
			A[i] = sc.nextInt();
		} {
			A[i] = sc.nextInt();
		} A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int cnt = 0; cnt 0 for (int i = N - 1; i >= 0; i--) {
			for (int j = 0; j < i; j++) {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			}
		} int i = N - 1; int i = N - 1; i N - 1 N 1 i >= 0 i 0 i-- i-- i {
			for (int j = 0; j < i; j++) {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			}
		} {
			for (int j = 0; j < i; j++) {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			}
		} for (int j = 0; j < i; j++) {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			} int j = 0; int j = 0; j 0 j < i j i j++ j++ j {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			} {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			} if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				} 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;
					cnt++;
				} 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 cnt++ cnt for (int i = 0; i < A.length; i++) {
			System.out.print((i == 0 ? "" : " ") + A[i]);
		} int i = 0; int i = 0; i 0 i < A.length i A.length A A.length i++ i++ i {
			System.out.print((i == 0 ? "" : " ") + A[i]);
		} {
			System.out.print((i == 0 ? "" : " ") + A[i]);
		} System.out.print((i == 0 ? "" : " ") + A[i]) System.out.print System.out System System.out (i == 0 ? "" : " ") + A[i] (i == 0 ? "" : " ") i == 0 i 0 "" " " A[i] A i System.out.println("\n" + cnt) System.out.println System.out System System.out "\n" + cnt "\n" cnt 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 {
	Scanner sc = new Scanner(System.in);
	StringBuilder out;

	void run() {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		}

		int cnt = 0;
		for (int i = N - 1; i >= 0; i--) {
			for (int j = 0; j < i; j++) {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			}
		}
		for (int i = 0; i < A.length; i++) {
			System.out.print((i == 0 ? "" : " ") + A[i]);
		}
		System.out.println("\n" + cnt);
	}

	public static void main(String[] args) {
		new Main().run();
	}
} public class Main {
	Scanner sc = new Scanner(System.in);
	StringBuilder out;

	void run() {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		}

		int cnt = 0;
		for (int i = N - 1; i >= 0; i--) {
			for (int j = 0; j < i; j++) {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			}
		}
		for (int i = 0; i < A.length; i++) {
			System.out.print((i == 0 ? "" : " ") + A[i]);
		}
		System.out.println("\n" + cnt);
	}

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

public class Main {
	Scanner sc = new Scanner(System.in);
	StringBuilder out;

	void run() {
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < A.length; i++) {
			A[i] = sc.nextInt();
		}

		int cnt = 0;
		for (int i = N - 1; i >= 0; i--) {
			for (int j = 0; j < i; j++) {
				if (A[j] > A[j + 1]) {
					int tmp = A[j];
					A[j] = A[j + 1];
					A[j + 1] = tmp;
					cnt++;
				}
			}
		}
		for (int i = 0; i < A.length; i++) {
			System.out.print((i == 0 ? "" : " ") + A[i]);
		}
		System.out.println("\n" + cnt);
	}

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