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