import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextInt();
		}
		boolean F = true;
		int j = 0;
		int times = 0;
		while (F==true) {
			F = false;
			for (int i=n-1; i>=j+1; i--) {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			}
			j++;
		}
		for (int x=0; x<n; x++) {
			out.print((x==0?"":" ")+ar[x]);
		}
		out.println();
		out.println(times);
	}
}
 import java.util.*; util.* java import static java.lang.System.*; import static java.lang.System.*; import static java.lang.System.*; public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextInt();
		}
		boolean F = true;
		int j = 0;
		int times = 0;
		while (F==true) {
			F = false;
			for (int i=n-1; i>=j+1; i--) {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			}
			j++;
		}
		for (int x=0; x<n; x++) {
			out.print((x==0?"":" ")+ar[x]);
		}
		out.println();
		out.println(times);
	}
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextInt();
		}
		boolean F = true;
		int j = 0;
		int times = 0;
		while (F==true) {
			F = false;
			for (int i=n-1; i>=j+1; i--) {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			}
			j++;
		}
		for (int x=0; x<n; x++) {
			out.print((x==0?"":" ")+ar[x]);
		}
		out.println();
		out.println(times);
	} main {
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextInt();
		}
		boolean F = true;
		int j = 0;
		int times = 0;
		while (F==true) {
			F = false;
			for (int i=n-1; i>=j+1; i--) {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			}
			j++;
		}
		for (int x=0; x<n; x++) {
			out.print((x==0?"":" ")+ar[x]);
		}
		out.println();
		out.println(times);
	} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] ar = new int[n]; ar new int[n] n for (int i=0; i<n; i++) {
			ar[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			ar[i] = sc.nextInt();
		} {
			ar[i] = sc.nextInt();
		} ar[i] = sc.nextInt() ar[i] ar i sc.nextInt() sc.nextInt sc boolean F = true; F true int j = 0; j 0 int times = 0; times 0 while (F==true) {
			F = false;
			for (int i=n-1; i>=j+1; i--) {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			}
			j++;
		} F==true F true {
			F = false;
			for (int i=n-1; i>=j+1; i--) {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			}
			j++;
		} F = false F false for (int i=n-1; i>=j+1; i--) {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			} int i=n-1; int i=n-1; i n-1 n 1 i>=j+1 i j+1 j 1 i-- i-- i {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			} {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			} if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				} ar[i] < ar[i-1] ar[i] ar i ar[i-1] ar i-1 i 1 {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				} int temp = ar[i]; temp ar[i] ar i ar[i] = ar[i-1] ar[i] ar i ar[i-1] ar i-1 i 1 ar[i-1] = temp ar[i-1] ar i-1 i 1 temp times++ times F = true F true j++ j for (int x=0; x<n; x++) {
			out.print((x==0?"":" ")+ar[x]);
		} int x=0; int x=0; x 0 x<n x n x++ x++ x {
			out.print((x==0?"":" ")+ar[x]);
		} {
			out.print((x==0?"":" ")+ar[x]);
		} out.print((x==0?"":" ")+ar[x]) out.print out (x==0?"":" ")+ar[x] (x==0?"":" ") x==0 x 0 "" " " ar[x] ar x out.println() out.println out out.println(times) out.println out times String[] args args public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextInt();
		}
		boolean F = true;
		int j = 0;
		int times = 0;
		while (F==true) {
			F = false;
			for (int i=n-1; i>=j+1; i--) {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			}
			j++;
		}
		for (int x=0; x<n; x++) {
			out.print((x==0?"":" ")+ar[x]);
		}
		out.println();
		out.println(times);
	}
} public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextInt();
		}
		boolean F = true;
		int j = 0;
		int times = 0;
		while (F==true) {
			F = false;
			for (int i=n-1; i>=j+1; i--) {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			}
			j++;
		}
		for (int x=0; x<n; x++) {
			out.print((x==0?"":" ")+ar[x]);
		}
		out.println();
		out.println(times);
	}
} Main
import java.util.*;
import static java.lang.System.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int[] ar = new int[n];
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextInt();
		}
		boolean F = true;
		int j = 0;
		int times = 0;
		while (F==true) {
			F = false;
			for (int i=n-1; i>=j+1; i--) {
				if (ar[i] < ar[i-1]) {
					int temp = ar[i];
					ar[i] = ar[i-1];
					ar[i-1] = temp;
					times++;
					F = true;
				}
				
			}
			j++;
		}
		for (int x=0; x<n; x++) {
			out.print((x==0?"":" ")+ar[x]);
		}
		out.println();
		out.println(times);
	}
}

