import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = in.nextInt();
		}
		bubbleSort(c);
		in.close();
	}

	private static void bubbleSort(int[] A) {
		int flg = 1;
		int wk;
		int count=0;
		while (flg == 1) {
			flg = 0;
			for (int i = A.length - 1; i > 0; i--) {
				wk = A[i - 1];

				if (A[i] < A[i - 1]) {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				}
			}

		}
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<A.length;i++) {
			if(i>0) {
				sb.append(" ");
			}
			sb.append(A[i]);

		}
		System.out.println(sb.toString());
		System.out.println(count);
	}

}
 import java.util.Scanner; Scanner java.util class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = in.nextInt();
		}
		bubbleSort(c);
		in.close();
	}

	private static void bubbleSort(int[] A) {
		int flg = 1;
		int wk;
		int count=0;
		while (flg == 1) {
			flg = 0;
			for (int i = A.length - 1; i > 0; i--) {
				wk = A[i - 1];

				if (A[i] < A[i - 1]) {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				}
			}

		}
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<A.length;i++) {
			if(i>0) {
				sb.append(" ");
			}
			sb.append(A[i]);

		}
		System.out.println(sb.toString());
		System.out.println(count);
	}

} Main public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = in.nextInt();
		}
		bubbleSort(c);
		in.close();
	} main {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = in.nextInt();
		}
		bubbleSort(c);
		in.close();
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int n = in.nextInt(); n in.nextInt() in.nextInt in int[] c = new int[n]; c new int[n] n for (int i = 0; i < n; i++) {
			c[i] = in.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			c[i] = in.nextInt();
		} {
			c[i] = in.nextInt();
		} c[i] = in.nextInt() c[i] c i in.nextInt() in.nextInt in bubbleSort(c) bubbleSort c in.close() in.close in String args[] args private static void bubbleSort(int[] A) {
		int flg = 1;
		int wk;
		int count=0;
		while (flg == 1) {
			flg = 0;
			for (int i = A.length - 1; i > 0; i--) {
				wk = A[i - 1];

				if (A[i] < A[i - 1]) {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				}
			}

		}
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<A.length;i++) {
			if(i>0) {
				sb.append(" ");
			}
			sb.append(A[i]);

		}
		System.out.println(sb.toString());
		System.out.println(count);
	} bubbleSort {
		int flg = 1;
		int wk;
		int count=0;
		while (flg == 1) {
			flg = 0;
			for (int i = A.length - 1; i > 0; i--) {
				wk = A[i - 1];

				if (A[i] < A[i - 1]) {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				}
			}

		}
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<A.length;i++) {
			if(i>0) {
				sb.append(" ");
			}
			sb.append(A[i]);

		}
		System.out.println(sb.toString());
		System.out.println(count);
	} int flg = 1; flg 1 int wk; wk int count=0; count 0 while (flg == 1) {
			flg = 0;
			for (int i = A.length - 1; i > 0; i--) {
				wk = A[i - 1];

				if (A[i] < A[i - 1]) {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				}
			}

		} flg == 1 flg 1 {
			flg = 0;
			for (int i = A.length - 1; i > 0; i--) {
				wk = A[i - 1];

				if (A[i] < A[i - 1]) {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				}
			}

		} flg = 0 flg 0 for (int i = A.length - 1; i > 0; i--) {
				wk = A[i - 1];

				if (A[i] < A[i - 1]) {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				}
			} int i = A.length - 1; int i = A.length - 1; i A.length - 1 A.length A A.length 1 i > 0 i 0 i-- i-- i {
				wk = A[i - 1];

				if (A[i] < A[i - 1]) {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				}
			} {
				wk = A[i - 1];

				if (A[i] < A[i - 1]) {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				}
			} wk = A[i - 1] wk A[i - 1] A i - 1 i 1 if (A[i] < A[i - 1]) {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				} A[i] < A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				} A[i - 1] = A[i] A[i - 1] A i - 1 i 1 A[i] A i A[i] = wk A[i] A i wk count+=1 count 1 flg=1 flg 1 StringBuilder sb=new StringBuilder(); sb new StringBuilder() for(int i=0;i<A.length;i++) {
			if(i>0) {
				sb.append(" ");
			}
			sb.append(A[i]);

		} int i=0; int i=0; i 0 i<A.length i A.length A A.length i++ i++ i {
			if(i>0) {
				sb.append(" ");
			}
			sb.append(A[i]);

		} {
			if(i>0) {
				sb.append(" ");
			}
			sb.append(A[i]);

		} if(i>0) {
				sb.append(" ");
			} i>0 i 0 {
				sb.append(" ");
			} sb.append(" ") sb.append sb " " sb.append(A[i]) sb.append sb A[i] A i System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb System.out.println(count) System.out.println System.out System System.out count int[] A A
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] c = new int[n];
		for (int i = 0; i < n; i++) {
			c[i] = in.nextInt();
		}
		bubbleSort(c);
		in.close();
	}

	private static void bubbleSort(int[] A) {
		int flg = 1;
		int wk;
		int count=0;
		while (flg == 1) {
			flg = 0;
			for (int i = A.length - 1; i > 0; i--) {
				wk = A[i - 1];

				if (A[i] < A[i - 1]) {
					A[i - 1] = A[i];
					A[i] = wk;
					count+=1;
					flg=1;
				}
			}

		}
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<A.length;i++) {
			if(i>0) {
				sb.append(" ");
			}
			sb.append(A[i]);

		}
		System.out.println(sb.toString());
		System.out.println(count);
	}

}

