import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n, i, j, num[], count = 0;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		num = new int[n];
		for (i = 0; i < n; ++i) {
			num[i] = sc.nextInt();
		}
		sc.close();
		i = 1;
		while (i != 0) {
			i = 0;
			for (j = n - 1; j > 0; --j) {
				if (num[j - 1] > num[j]) {
					int tmp = num[j];
					num[j] = num[j - 1];
					num[j - 1] = tmp;
					i = 1;
					++count;
				}
			}
		}
		for (i = 0; i < n; ++i) {
			System.out.print(num[i]);
			if (i != n - 1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
		System.out.println(count);
	}
}
 import java.util.Scanner; Scanner java.util public class Main {

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

	public static void main(String[] args) {
		int n, i, j, num[], count = 0;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		num = new int[n];
		for (i = 0; i < n; ++i) {
			num[i] = sc.nextInt();
		}
		sc.close();
		i = 1;
		while (i != 0) {
			i = 0;
			for (j = n - 1; j > 0; --j) {
				if (num[j - 1] > num[j]) {
					int tmp = num[j];
					num[j] = num[j - 1];
					num[j - 1] = tmp;
					i = 1;
					++count;
				}
			}
		}
		for (i = 0; i < n; ++i) {
			System.out.print(num[i]);
			if (i != n - 1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
		System.out.println(count);
	}
} public class Main {

	public static void main(String[] args) {
		int n, i, j, num[], count = 0;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		num = new int[n];
		for (i = 0; i < n; ++i) {
			num[i] = sc.nextInt();
		}
		sc.close();
		i = 1;
		while (i != 0) {
			i = 0;
			for (j = n - 1; j > 0; --j) {
				if (num[j - 1] > num[j]) {
					int tmp = num[j];
					num[j] = num[j - 1];
					num[j - 1] = tmp;
					i = 1;
					++count;
				}
			}
		}
		for (i = 0; i < n; ++i) {
			System.out.print(num[i]);
			if (i != n - 1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
		System.out.println(count);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n, i, j, num[], count = 0;
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		num = new int[n];
		for (i = 0; i < n; ++i) {
			num[i] = sc.nextInt();
		}
		sc.close();
		i = 1;
		while (i != 0) {
			i = 0;
			for (j = n - 1; j > 0; --j) {
				if (num[j - 1] > num[j]) {
					int tmp = num[j];
					num[j] = num[j - 1];
					num[j - 1] = tmp;
					i = 1;
					++count;
				}
			}
		}
		for (i = 0; i < n; ++i) {
			System.out.print(num[i]);
			if (i != n - 1) {
				System.out.print(" ");
			}
		}
		System.out.print("\n");
		System.out.println(count);
	}
}

