import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ints = new int[n];
		for (int i=0; i<n; i++) {
			ints[i] = sc.nextInt();
		}
		
		int count = 0;
		while (true) {
			boolean flag = false;
			for (int i=0; i<n-1; i++) {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			}
			if (flag==false) {break;}
		}
		
		for (int i=0; i<n; i++) {
			System.out.print(ints[i]);
			if (i!=n-1) {System.out.print(" ");}
		}
		System.out.println();
		System.out.println(count);
	}
}			 import java.util.*; util.* java public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ints = new int[n];
		for (int i=0; i<n; i++) {
			ints[i] = sc.nextInt();
		}
		
		int count = 0;
		while (true) {
			boolean flag = false;
			for (int i=0; i<n-1; i++) {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			}
			if (flag==false) {break;}
		}
		
		for (int i=0; i<n; i++) {
			System.out.print(ints[i]);
			if (i!=n-1) {System.out.print(" ");}
		}
		System.out.println();
		System.out.println(count);
	}
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ints = new int[n];
		for (int i=0; i<n; i++) {
			ints[i] = sc.nextInt();
		}
		
		int count = 0;
		while (true) {
			boolean flag = false;
			for (int i=0; i<n-1; i++) {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			}
			if (flag==false) {break;}
		}
		
		for (int i=0; i<n; i++) {
			System.out.print(ints[i]);
			if (i!=n-1) {System.out.print(" ");}
		}
		System.out.println();
		System.out.println(count);
	} main {
		int n = sc.nextInt();
		int[] ints = new int[n];
		for (int i=0; i<n; i++) {
			ints[i] = sc.nextInt();
		}
		
		int count = 0;
		while (true) {
			boolean flag = false;
			for (int i=0; i<n-1; i++) {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			}
			if (flag==false) {break;}
		}
		
		for (int i=0; i<n; i++) {
			System.out.print(ints[i]);
			if (i!=n-1) {System.out.print(" ");}
		}
		System.out.println();
		System.out.println(count);
	} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] ints = new int[n]; ints new int[n] n for (int i=0; i<n; i++) {
			ints[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			ints[i] = sc.nextInt();
		} {
			ints[i] = sc.nextInt();
		} ints[i] = sc.nextInt() ints[i] ints i sc.nextInt() sc.nextInt sc int count = 0; count 0 while (true) {
			boolean flag = false;
			for (int i=0; i<n-1; i++) {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			}
			if (flag==false) {break;}
		} true {
			boolean flag = false;
			for (int i=0; i<n-1; i++) {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			}
			if (flag==false) {break;}
		} boolean flag = false; flag false for (int i=0; i<n-1; i++) {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			} int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			} {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			} if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				} ints[i] > ints[i+1] ints[i] ints i ints[i+1] ints i+1 i 1 {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				} int temp = ints[i]; temp ints[i] ints i ints[i] = ints[i+1] ints[i] ints i ints[i+1] ints i+1 i 1 ints[i+1] = temp ints[i+1] ints i+1 i 1 temp flag = true flag true count++ count if (flag==false) {break;} flag==false flag false {break;} break; for (int i=0; i<n; i++) {
			System.out.print(ints[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(ints[i]);
			if (i!=n-1) {System.out.print(" ");}
		} {
			System.out.print(ints[i]);
			if (i!=n-1) {System.out.print(" ");}
		} System.out.print(ints[i]) System.out.print System.out System System.out ints[i] ints 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.println() System.out.println System.out System System.out System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ints = new int[n];
		for (int i=0; i<n; i++) {
			ints[i] = sc.nextInt();
		}
		
		int count = 0;
		while (true) {
			boolean flag = false;
			for (int i=0; i<n-1; i++) {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			}
			if (flag==false) {break;}
		}
		
		for (int i=0; i<n; i++) {
			System.out.print(ints[i]);
			if (i!=n-1) {System.out.print(" ");}
		}
		System.out.println();
		System.out.println(count);
	}
} public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ints = new int[n];
		for (int i=0; i<n; i++) {
			ints[i] = sc.nextInt();
		}
		
		int count = 0;
		while (true) {
			boolean flag = false;
			for (int i=0; i<n-1; i++) {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			}
			if (flag==false) {break;}
		}
		
		for (int i=0; i<n; i++) {
			System.out.print(ints[i]);
			if (i!=n-1) {System.out.print(" ");}
		}
		System.out.println();
		System.out.println(count);
	}
} Main
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ints = new int[n];
		for (int i=0; i<n; i++) {
			ints[i] = sc.nextInt();
		}
		
		int count = 0;
		while (true) {
			boolean flag = false;
			for (int i=0; i<n-1; i++) {
				if (ints[i] > ints[i+1]) {
					int temp = ints[i];
					ints[i] = ints[i+1];
					ints[i+1] = temp;
					flag = true;
					count++;
				}
			}
			if (flag==false) {break;}
		}
		
		for (int i=0; i<n; i++) {
			System.out.print(ints[i]);
			if (i!=n-1) {System.out.print(" ");}
		}
		System.out.println();
		System.out.println(count);
	}
}			
