import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] ary = new int[n];

		for (int i=0; i<n; i++) {
			ary[i] = stdIn.nextInt();
		}

		int count = 0;
		for (int i=0; i<ary.length; i++) {
			for (int j=ary.length-1; j>i; j--) {
				if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				}
			}
		}

		for (int i=0; i<ary.length-1; i++) {
			System.out.print(ary[i] + " ");
		}
		System.out.println(ary[ary.length-1]);
		System.out.println(count);
	}

	static void swap(int[] ary,int x,int y){
		int temp = ary[x];
		ary[x] = ary[y];
		ary[y] = temp;
	}
} import java.util.*; util.* java class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] ary = new int[n];

		for (int i=0; i<n; i++) {
			ary[i] = stdIn.nextInt();
		}

		int count = 0;
		for (int i=0; i<ary.length; i++) {
			for (int j=ary.length-1; j>i; j--) {
				if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				}
			}
		}

		for (int i=0; i<ary.length-1; i++) {
			System.out.print(ary[i] + " ");
		}
		System.out.println(ary[ary.length-1]);
		System.out.println(count);
	}

	static void swap(int[] ary,int x,int y){
		int temp = ary[x];
		ary[x] = ary[y];
		ary[y] = temp;
	}
} Main public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] ary = new int[n];

		for (int i=0; i<n; i++) {
			ary[i] = stdIn.nextInt();
		}

		int count = 0;
		for (int i=0; i<ary.length; i++) {
			for (int j=ary.length-1; j>i; j--) {
				if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				}
			}
		}

		for (int i=0; i<ary.length-1; i++) {
			System.out.print(ary[i] + " ");
		}
		System.out.println(ary[ary.length-1]);
		System.out.println(count);
	} main {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] ary = new int[n];

		for (int i=0; i<n; i++) {
			ary[i] = stdIn.nextInt();
		}

		int count = 0;
		for (int i=0; i<ary.length; i++) {
			for (int j=ary.length-1; j>i; j--) {
				if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				}
			}
		}

		for (int i=0; i<ary.length-1; i++) {
			System.out.print(ary[i] + " ");
		}
		System.out.println(ary[ary.length-1]);
		System.out.println(count);
	} Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int[] ary = new int[n]; ary new int[n] n for (int i=0; i<n; i++) {
			ary[i] = stdIn.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			ary[i] = stdIn.nextInt();
		} {
			ary[i] = stdIn.nextInt();
		} ary[i] = stdIn.nextInt() ary[i] ary i stdIn.nextInt() stdIn.nextInt stdIn int count = 0; count 0 for (int i=0; i<ary.length; i++) {
			for (int j=ary.length-1; j>i; j--) {
				if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				}
			}
		} int i=0; int i=0; i 0 i<ary.length i ary.length ary ary.length i++ i++ i {
			for (int j=ary.length-1; j>i; j--) {
				if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				}
			}
		} {
			for (int j=ary.length-1; j>i; j--) {
				if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				}
			}
		} for (int j=ary.length-1; j>i; j--) {
				if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				}
			} int j=ary.length-1; int j=ary.length-1; j ary.length-1 ary.length ary ary.length 1 j>i j i j-- j-- j {
				if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				}
			} {
				if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				}
			} if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				} ary[j] < ary[j-1] ary[j] ary j ary[j-1] ary j-1 j 1 {
					swap(ary,j,j-1);
					count++;
				} swap(ary,j,j-1) swap ary j j-1 j 1 count++ count for (int i=0; i<ary.length-1; i++) {
			System.out.print(ary[i] + " ");
		} int i=0; int i=0; i 0 i<ary.length-1 i ary.length-1 ary.length ary ary.length 1 i++ i++ i {
			System.out.print(ary[i] + " ");
		} {
			System.out.print(ary[i] + " ");
		} System.out.print(ary[i] + " ") System.out.print System.out System System.out ary[i] + " " ary[i] ary i " " System.out.println(ary[ary.length-1]) System.out.println System.out System System.out ary[ary.length-1] ary ary.length-1 ary.length ary ary.length 1 System.out.println(count) System.out.println System.out System System.out count String[] args args static void swap(int[] ary,int x,int y){
		int temp = ary[x];
		ary[x] = ary[y];
		ary[y] = temp;
	} swap {
		int temp = ary[x];
		ary[x] = ary[y];
		ary[y] = temp;
	} int temp = ary[x]; temp ary[x] ary x ary[x] = ary[y] ary[x] ary x ary[y] ary y ary[y] = temp ary[y] ary y temp int[] ary ary int x x int y y
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		int[] ary = new int[n];

		for (int i=0; i<n; i++) {
			ary[i] = stdIn.nextInt();
		}

		int count = 0;
		for (int i=0; i<ary.length; i++) {
			for (int j=ary.length-1; j>i; j--) {
				if (ary[j] < ary[j-1]) {
					swap(ary,j,j-1);
					count++;
				}
			}
		}

		for (int i=0; i<ary.length-1; i++) {
			System.out.print(ary[i] + " ");
		}
		System.out.println(ary[ary.length-1]);
		System.out.println(count);
	}

	static void swap(int[] ary,int x,int y){
		int temp = ary[x];
		ary[x] = ary[y];
		ary[y] = temp;
	}
}