import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] kari = line2.split(" ");
		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = Integer.parseInt(kari[i]);
		}

		int answer = 0;

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

		StringBuilder str = new StringBuilder();

		for (int i = 0; i < n - 1; i++) {
			str.append(num[i]);
			str.append(" ");
		}
		str.append(num[n - 1]);

		System.out.println(str);
		System.out.println(answer);

	}

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

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] kari = line2.split(" ");
		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = Integer.parseInt(kari[i]);
		}

		int answer = 0;

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

		StringBuilder str = new StringBuilder();

		for (int i = 0; i < n - 1; i++) {
			str.append(num[i]);
			str.append(" ");
		}
		str.append(num[n - 1]);

		System.out.println(str);
		System.out.println(answer);

	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] kari = line2.split(" ");
		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = Integer.parseInt(kari[i]);
		}

		int answer = 0;

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

		StringBuilder str = new StringBuilder();

		for (int i = 0; i < n - 1; i++) {
			str.append(num[i]);
			str.append(" ");
		}
		str.append(num[n - 1]);

		System.out.println(str);
		System.out.println(answer);

	} main {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] kari = line2.split(" ");
		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = Integer.parseInt(kari[i]);
		}

		int answer = 0;

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

		StringBuilder str = new StringBuilder();

		for (int i = 0; i < n - 1; i++) {
			str.append(num[i]);
			str.append(" ");
		}
		str.append(num[n - 1]);

		System.out.println(str);
		System.out.println(answer);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line1 = sc.nextLine(); line1 sc.nextLine() sc.nextLine sc int n = Integer.parseInt(line1); n Integer.parseInt(line1) Integer.parseInt Integer line1 String line2 = sc.nextLine(); line2 sc.nextLine() sc.nextLine sc String[] kari = line2.split(" "); kari line2.split(" ") line2.split line2 " " int[] num = new int[n]; num new int[n] n for (int i = 0; i < n; i++) {
			num[i] = Integer.parseInt(kari[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			num[i] = Integer.parseInt(kari[i]);
		} {
			num[i] = Integer.parseInt(kari[i]);
		} num[i] = Integer.parseInt(kari[i]) num[i] num i Integer.parseInt(kari[i]) Integer.parseInt Integer kari[i] kari i int answer = 0; answer 0 for (int i = 0; i < n - 1; i++) {
			for (int j = n - 1; j > i; j--) {
				if (num[j - 1] > num[j]) {
					int v = num[j];
					num[j] = num[j - 1];
					num[j - 1] = v;
					answer++;
				}
			}
		} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			for (int j = n - 1; j > i; j--) {
				if (num[j - 1] > num[j]) {
					int v = num[j];
					num[j] = num[j - 1];
					num[j - 1] = v;
					answer++;
				}
			}
		} {
			for (int j = n - 1; j > i; j--) {
				if (num[j - 1] > num[j]) {
					int v = num[j];
					num[j] = num[j - 1];
					num[j - 1] = v;
					answer++;
				}
			}
		} for (int j = n - 1; j > i; j--) {
				if (num[j - 1] > num[j]) {
					int v = num[j];
					num[j] = num[j - 1];
					num[j - 1] = v;
					answer++;
				}
			} int j = n - 1; int j = n - 1; j n - 1 n 1 j > i j i j-- j-- j {
				if (num[j - 1] > num[j]) {
					int v = num[j];
					num[j] = num[j - 1];
					num[j - 1] = v;
					answer++;
				}
			} {
				if (num[j - 1] > num[j]) {
					int v = num[j];
					num[j] = num[j - 1];
					num[j - 1] = v;
					answer++;
				}
			} if (num[j - 1] > num[j]) {
					int v = num[j];
					num[j] = num[j - 1];
					num[j - 1] = v;
					answer++;
				} num[j - 1] > num[j] num[j - 1] num j - 1 j 1 num[j] num j {
					int v = num[j];
					num[j] = num[j - 1];
					num[j - 1] = v;
					answer++;
				} int v = num[j]; v num[j] num j num[j] = num[j - 1] num[j] num j num[j - 1] num j - 1 j 1 num[j - 1] = v num[j - 1] num j - 1 j 1 v answer++ answer StringBuilder str = new StringBuilder(); str new StringBuilder() for (int i = 0; i < n - 1; i++) {
			str.append(num[i]);
			str.append(" ");
		} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			str.append(num[i]);
			str.append(" ");
		} {
			str.append(num[i]);
			str.append(" ");
		} str.append(num[i]) str.append str num[i] num i str.append(" ") str.append str " " str.append(num[n - 1]) str.append str num[n - 1] num n - 1 n 1 System.out.println(str) System.out.println System.out System System.out str System.out.println(answer) System.out.println System.out System System.out answer String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] kari = line2.split(" ");
		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = Integer.parseInt(kari[i]);
		}

		int answer = 0;

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

		StringBuilder str = new StringBuilder();

		for (int i = 0; i < n - 1; i++) {
			str.append(num[i]);
			str.append(" ");
		}
		str.append(num[n - 1]);

		System.out.println(str);
		System.out.println(answer);

	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] kari = line2.split(" ");
		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = Integer.parseInt(kari[i]);
		}

		int answer = 0;

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

		StringBuilder str = new StringBuilder();

		for (int i = 0; i < n - 1; i++) {
			str.append(num[i]);
			str.append(" ");
		}
		str.append(num[n - 1]);

		System.out.println(str);
		System.out.println(answer);

	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		String line1 = sc.nextLine();
		int n = Integer.parseInt(line1);

		String line2 = sc.nextLine();
		String[] kari = line2.split(" ");
		int[] num = new int[n];
		for (int i = 0; i < n; i++) {
			num[i] = Integer.parseInt(kari[i]);
		}

		int answer = 0;

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

		StringBuilder str = new StringBuilder();

		for (int i = 0; i < n - 1; i++) {
			str.append(num[i]);
			str.append(" ");
		}
		str.append(num[n - 1]);

		System.out.println(str);
		System.out.println(answer);

	}

}