import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int count = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

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

	}
	static void print(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length-1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
	}

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

	public static void main(String[] args) {

		int count = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

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

	}
	static void print(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length-1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
	}

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

		int count = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

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

	} main {

		int count = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

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

	} int count = 0; count 0 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) 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 < n; i++) {
			a[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = sc.nextInt();
		} {
			a[i] = sc.nextInt();
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc for (int i = n-1; i >= 0; i--) {
			for (int j = n-1; j > 0; j--) {
				int tmp = a[j];
				if (a[j] < a[j-1]) {
					a[j] = a[j-1];
					a[j-1] = tmp;
					count++;
				}
			}
		} int i = n-1; int i = n-1; i n-1 n 1 i >= 0 i 0 i-- i-- i {
			for (int j = n-1; j > 0; j--) {
				int tmp = a[j];
				if (a[j] < a[j-1]) {
					a[j] = a[j-1];
					a[j-1] = tmp;
					count++;
				}
			}
		} {
			for (int j = n-1; j > 0; j--) {
				int tmp = a[j];
				if (a[j] < a[j-1]) {
					a[j] = a[j-1];
					a[j-1] = tmp;
					count++;
				}
			}
		} for (int j = n-1; j > 0; j--) {
				int tmp = a[j];
				if (a[j] < a[j-1]) {
					a[j] = a[j-1];
					a[j-1] = tmp;
					count++;
				}
			} int j = n-1; int j = n-1; j n-1 n 1 j > 0 j 0 j-- j-- j {
				int tmp = a[j];
				if (a[j] < a[j-1]) {
					a[j] = a[j-1];
					a[j-1] = tmp;
					count++;
				}
			} {
				int tmp = a[j];
				if (a[j] < a[j-1]) {
					a[j] = a[j-1];
					a[j-1] = tmp;
					count++;
				}
			} int tmp = a[j]; tmp a[j] a j if (a[j] < a[j-1]) {
					a[j] = a[j-1];
					a[j-1] = tmp;
					count++;
				} a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 {
					a[j] = a[j-1];
					a[j-1] = tmp;
					count++;
				} 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 count++ count print(a) print a System.out.println(count) System.out.println System.out System System.out count String[] args args static void print(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length-1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
	} print {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length-1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
	} for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length-1) {
				System.out.print(" ");
			}
		} int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
			System.out.print(a[i]);
			if (i != a.length-1) {
				System.out.print(" ");
			}
		} {
			System.out.print(a[i]);
			if (i != a.length-1) {
				System.out.print(" ");
			}
		} System.out.print(a[i]) System.out.print System.out System System.out a[i] a i if (i != a.length-1) {
				System.out.print(" ");
			} i != a.length-1 i a.length-1 a.length a a.length 1 {
				System.out.print(" ");
			} System.out.print(" ") System.out.print System.out System System.out " " System.out.print("\n") System.out.print System.out System System.out "\n" int[] a a public class Main {

	public static void main(String[] args) {

		int count = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

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

	}
	static void print(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length-1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
	}

} public class Main {

	public static void main(String[] args) {

		int count = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

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

	}
	static void print(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length-1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		int count = 0;
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt();
		}

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

	}
	static void print(int[] a) {
		for (int i = 0; i < a.length; i++) {
			System.out.print(a[i]);
			if (i != a.length-1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
	}

}

