import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int num[] = new int[n];

		for (int i = 0; i < n; i++) {
			num[i] = scan.nextInt();
		}

		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (num[j] < num[j - 1]) {
					int tmp = num[j];
					num[j] = num[j - 1];
					num[j - 1] = tmp;
					count++;
				}
			}
		}

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

		System.out.println();
		System.out.println(count);
		scan.close();
	}

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int num[] = new int[n];

		for (int i = 0; i < n; i++) {
			num[i] = scan.nextInt();
		}

		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (num[j] < num[j - 1]) {
					int tmp = num[j];
					num[j] = num[j - 1];
					num[j - 1] = tmp;
					count++;
				}
			}
		}

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

		System.out.println();
		System.out.println(count);
		scan.close();
	}

} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int num[] = new int[n];

		for (int i = 0; i < n; i++) {
			num[i] = scan.nextInt();
		}

		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (num[j] < num[j - 1]) {
					int tmp = num[j];
					num[j] = num[j - 1];
					num[j - 1] = tmp;
					count++;
				}
			}
		}

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

		System.out.println();
		System.out.println(count);
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int num[] = new int[n];

		for (int i = 0; i < n; i++) {
			num[i] = scan.nextInt();
		}

		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (num[j] < num[j - 1]) {
					int tmp = num[j];
					num[j] = num[j - 1];
					num[j - 1] = tmp;
					count++;
				}
			}
		}

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

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

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int num[] = new int[n];

		for (int i = 0; i < n; i++) {
			num[i] = scan.nextInt();
		}

		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (num[j] < num[j - 1]) {
					int tmp = num[j];
					num[j] = num[j - 1];
					num[j - 1] = tmp;
					count++;
				}
			}
		}

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

		System.out.println();
		System.out.println(count);
		scan.close();
	}

} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int num[] = new int[n];

		for (int i = 0; i < n; i++) {
			num[i] = scan.nextInt();
		}

		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (num[j] < num[j - 1]) {
					int tmp = num[j];
					num[j] = num[j - 1];
					num[j - 1] = tmp;
					count++;
				}
			}
		}

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

		System.out.println();
		System.out.println(count);
		scan.close();
	}

} Main
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int num[] = new int[n];

		for (int i = 0; i < n; i++) {
			num[i] = scan.nextInt();
		}

		int count = 0;

		for (int i = 0; i < n; i++) {
			for (int j = n - 1; j >= i + 1; j--) {
				if (num[j] < num[j - 1]) {
					int tmp = num[j];
					num[j] = num[j - 1];
					num[j - 1] = tmp;
					count++;
				}
			}
		}

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

		System.out.println();
		System.out.println(count);
		scan.close();
	}

}