import java.util.Scanner;
public class Main {
	int n;
	int list[];
	public static void main(String args[]) {
		new Main();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		list = new int[n];
		for (int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		boolean flag = true;
		int cnt = 0;
		while (flag) {
			flag = false;
			for (int i = 1; i < n; i++) {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			}
		}
		this.writeArray();
		System.out.println(cnt);
	}
	public void writeArray() {
		System.out.print(list[0]);
		for (int i = 1; i < n; i++) {
			System.out.print(" " + list[i]);
		}
		System.out.println();
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	int n;
	int list[];
	public static void main(String args[]) {
		new Main();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		list = new int[n];
		for (int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		boolean flag = true;
		int cnt = 0;
		while (flag) {
			flag = false;
			for (int i = 1; i < n; i++) {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			}
		}
		this.writeArray();
		System.out.println(cnt);
	}
	public void writeArray() {
		System.out.print(list[0]);
		for (int i = 1; i < n; i++) {
			System.out.print(" " + list[i]);
		}
		System.out.println();
	}
} Main int n; n int list[]; list public static void main(String args[]) {
		new Main();
	} main {
		new Main();
	} new Main() String args[] args Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		list = new int[n];
		for (int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		boolean flag = true;
		int cnt = 0;
		while (flag) {
			flag = false;
			for (int i = 1; i < n; i++) {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			}
		}
		this.writeArray();
		System.out.println(cnt);
	} Main {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		list = new int[n];
		for (int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		boolean flag = true;
		int cnt = 0;
		while (flag) {
			flag = false;
			for (int i = 1; i < n; i++) {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			}
		}
		this.writeArray();
		System.out.println(cnt);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) n = scan.nextInt() n scan.nextInt() scan.nextInt scan list = new int[n] list new int[n] n for (int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			list[i] = scan.nextInt();
		} {
			list[i] = scan.nextInt();
		} list[i] = scan.nextInt() list[i] list i scan.nextInt() scan.nextInt scan boolean flag = true; flag true int cnt = 0; cnt 0 while (flag) {
			flag = false;
			for (int i = 1; i < n; i++) {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			}
		} flag {
			flag = false;
			for (int i = 1; i < n; i++) {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			}
		} flag = false flag false for (int i = 1; i < n; i++) {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			} {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			} if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				} list[i] < list[i-1] list[i] list i list[i-1] list i-1 i 1 {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				} int tmp = list[i]; tmp list[i] list i list[i] = list[i-1] list[i] list i list[i-1] list i-1 i 1 list[i-1] = tmp list[i-1] list i-1 i 1 tmp cnt++ cnt flag = true flag true this.writeArray() this.writeArray this System.out.println(cnt) System.out.println System.out System System.out cnt public void writeArray() {
		System.out.print(list[0]);
		for (int i = 1; i < n; i++) {
			System.out.print(" " + list[i]);
		}
		System.out.println();
	} writeArray {
		System.out.print(list[0]);
		for (int i = 1; i < n; i++) {
			System.out.print(" " + list[i]);
		}
		System.out.println();
	} System.out.print(list[0]) System.out.print System.out System System.out list[0] list 0 for (int i = 1; i < n; i++) {
			System.out.print(" " + list[i]);
		} int i = 1; int i = 1; i 1 i < n i n i++ i++ i {
			System.out.print(" " + list[i]);
		} {
			System.out.print(" " + list[i]);
		} System.out.print(" " + list[i]) System.out.print System.out System System.out " " + list[i] " " list[i] list i System.out.println() System.out.println System.out System System.out public class Main {
	int n;
	int list[];
	public static void main(String args[]) {
		new Main();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		list = new int[n];
		for (int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		boolean flag = true;
		int cnt = 0;
		while (flag) {
			flag = false;
			for (int i = 1; i < n; i++) {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			}
		}
		this.writeArray();
		System.out.println(cnt);
	}
	public void writeArray() {
		System.out.print(list[0]);
		for (int i = 1; i < n; i++) {
			System.out.print(" " + list[i]);
		}
		System.out.println();
	}
} public class Main {
	int n;
	int list[];
	public static void main(String args[]) {
		new Main();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		list = new int[n];
		for (int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		boolean flag = true;
		int cnt = 0;
		while (flag) {
			flag = false;
			for (int i = 1; i < n; i++) {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			}
		}
		this.writeArray();
		System.out.println(cnt);
	}
	public void writeArray() {
		System.out.print(list[0]);
		for (int i = 1; i < n; i++) {
			System.out.print(" " + list[i]);
		}
		System.out.println();
	}
} Main
import java.util.Scanner;
public class Main {
	int n;
	int list[];
	public static void main(String args[]) {
		new Main();
	}
	Main() {
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		list = new int[n];
		for (int i = 0; i < n; i++) {
			list[i] = scan.nextInt();
		}
		boolean flag = true;
		int cnt = 0;
		while (flag) {
			flag = false;
			for (int i = 1; i < n; i++) {
				if (list[i] < list[i-1]) {
					int tmp = list[i];
					list[i] = list[i-1];
					list[i-1] = tmp;
					cnt++;
					flag = true;
				}
			}
		}
		this.writeArray();
		System.out.println(cnt);
	}
	public void writeArray() {
		System.out.print(list[0]);
		for (int i = 1; i < n; i++) {
			System.out.print(" " + list[i]);
		}
		System.out.println();
	}
}

