import java.io.IOException;
import java.util.Scanner;
public class Main {
	static int count;
	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int[] a = new int[x];

		for(int i=0;i<x;i++) {
			a[i] = sc.nextInt();
		}

		bubbleSort(a, x);
		show(a, x, count);
		sc.close();
	}

	public static void bubbleSort(int[] a, int x) {
		boolean flag = true;
		count = 0;
		while(flag) {
			flag = false;
			for(int i=x-1;i>0;i--) {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			}
		}
	}

	public static void show(int[] a, int x, int count2) {
		for(int i=0;i<x;i++) {
			System.out.print(a[i]);
			if(i!=x-1) {
				System.out.print(" ");
			}
		}
		System.out.println();
		System.out.println(count);
	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util public class Main {
	static int count;
	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int[] a = new int[x];

		for(int i=0;i<x;i++) {
			a[i] = sc.nextInt();
		}

		bubbleSort(a, x);
		show(a, x, count);
		sc.close();
	}

	public static void bubbleSort(int[] a, int x) {
		boolean flag = true;
		count = 0;
		while(flag) {
			flag = false;
			for(int i=x-1;i>0;i--) {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			}
		}
	}

	public static void show(int[] a, int x, int count2) {
		for(int i=0;i<x;i++) {
			System.out.print(a[i]);
			if(i!=x-1) {
				System.out.print(" ");
			}
		}
		System.out.println();
		System.out.println(count);
	}
} Main static int count; count public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int[] a = new int[x];

		for(int i=0;i<x;i++) {
			a[i] = sc.nextInt();
		}

		bubbleSort(a, x);
		show(a, x, count);
		sc.close();
	} main {

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int[] a = new int[x];

		for(int i=0;i<x;i++) {
			a[i] = sc.nextInt();
		}

		bubbleSort(a, x);
		show(a, x, count);
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int x = sc.nextInt(); x sc.nextInt() sc.nextInt sc int[] a = new int[x]; a new int[x] x for(int i=0;i<x;i++) {
			a[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<x i x i++ i++ i {
			a[i] = sc.nextInt();
		} {
			a[i] = sc.nextInt();
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc bubbleSort(a, x) bubbleSort a x show(a, x, count) show a x count sc.close() sc.close sc String[] args args public static void bubbleSort(int[] a, int x) {
		boolean flag = true;
		count = 0;
		while(flag) {
			flag = false;
			for(int i=x-1;i>0;i--) {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			}
		}
	} bubbleSort {
		boolean flag = true;
		count = 0;
		while(flag) {
			flag = false;
			for(int i=x-1;i>0;i--) {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			}
		}
	} boolean flag = true; flag true count = 0 count 0 while(flag) {
			flag = false;
			for(int i=x-1;i>0;i--) {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			}
		} flag {
			flag = false;
			for(int i=x-1;i>0;i--) {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			}
		} flag = false flag false for(int i=x-1;i>0;i--) {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			} int i=x-1; int i=x-1; i x-1 x 1 i>0 i 0 i-- i-- i {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			} {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			} if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				} a[i]<a[i-1] a[i] a i a[i-1] a i-1 i 1 {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				} int tmp = a[i]; tmp a[i] a i a[i] = a[i-1] a[i] a i a[i-1] a i-1 i 1 a[i-1] = tmp a[i-1] a i-1 i 1 tmp flag = true flag true count++ count int[] a a int x x public static void show(int[] a, int x, int count2) {
		for(int i=0;i<x;i++) {
			System.out.print(a[i]);
			if(i!=x-1) {
				System.out.print(" ");
			}
		}
		System.out.println();
		System.out.println(count);
	} show {
		for(int i=0;i<x;i++) {
			System.out.print(a[i]);
			if(i!=x-1) {
				System.out.print(" ");
			}
		}
		System.out.println();
		System.out.println(count);
	} for(int i=0;i<x;i++) {
			System.out.print(a[i]);
			if(i!=x-1) {
				System.out.print(" ");
			}
		} int i=0; int i=0; i 0 i<x i x i++ i++ i {
			System.out.print(a[i]);
			if(i!=x-1) {
				System.out.print(" ");
			}
		} {
			System.out.print(a[i]);
			if(i!=x-1) {
				System.out.print(" ");
			}
		} System.out.print(a[i]) System.out.print System.out System System.out a[i] a i if(i!=x-1) {
				System.out.print(" ");
			} i!=x-1 i x-1 x 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 int[] a a int x x int count2 count2 public class Main {
	static int count;
	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int[] a = new int[x];

		for(int i=0;i<x;i++) {
			a[i] = sc.nextInt();
		}

		bubbleSort(a, x);
		show(a, x, count);
		sc.close();
	}

	public static void bubbleSort(int[] a, int x) {
		boolean flag = true;
		count = 0;
		while(flag) {
			flag = false;
			for(int i=x-1;i>0;i--) {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			}
		}
	}

	public static void show(int[] a, int x, int count2) {
		for(int i=0;i<x;i++) {
			System.out.print(a[i]);
			if(i!=x-1) {
				System.out.print(" ");
			}
		}
		System.out.println();
		System.out.println(count);
	}
} public class Main {
	static int count;
	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int[] a = new int[x];

		for(int i=0;i<x;i++) {
			a[i] = sc.nextInt();
		}

		bubbleSort(a, x);
		show(a, x, count);
		sc.close();
	}

	public static void bubbleSort(int[] a, int x) {
		boolean flag = true;
		count = 0;
		while(flag) {
			flag = false;
			for(int i=x-1;i>0;i--) {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			}
		}
	}

	public static void show(int[] a, int x, int count2) {
		for(int i=0;i<x;i++) {
			System.out.print(a[i]);
			if(i!=x-1) {
				System.out.print(" ");
			}
		}
		System.out.println();
		System.out.println(count);
	}
} Main
import java.io.IOException;
import java.util.Scanner;
public class Main {
	static int count;
	public static void main(String[] args) throws IOException{

		Scanner sc = new Scanner(System.in);

		int x = sc.nextInt();
		int[] a = new int[x];

		for(int i=0;i<x;i++) {
			a[i] = sc.nextInt();
		}

		bubbleSort(a, x);
		show(a, x, count);
		sc.close();
	}

	public static void bubbleSort(int[] a, int x) {
		boolean flag = true;
		count = 0;
		while(flag) {
			flag = false;
			for(int i=x-1;i>0;i--) {
				if(a[i]<a[i-1]) {
					int tmp = a[i];
					a[i] = a[i-1];
					a[i-1] = tmp;
					flag = true;
					count++;
				}
			}
		}
	}

	public static void show(int[] a, int x, int count2) {
		for(int i=0;i<x;i++) {
			System.out.print(a[i]);
			if(i!=x-1) {
				System.out.print(" ");
			}
		}
		System.out.println();
		System.out.println(count);
	}
}
