import java.util.Scanner;
public class Main{
private static Scanner scanner;
public static void main(String args[]) {
	scanner = new Scanner(System.in);
	int a = scanner.nextInt();
	int[] b = new int[a];
	int count = 0;
	//int flag = 1;
	for(int i = 0;i < a;i++) {
		b[i] = scanner.nextInt();
	}
	for(int i = 0;i < a;i++) {
			for(int j = a-1;j >= 1;j--) {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		}
	}
	for(int i = 0;i < a;i++) {
		System.out.print(b[i]);
		if(i == a - 1) {
			System.out.println("");
		}else {
			System.out.print(" ");
		}
	}
	System.out.println(count);
}
}
 import java.util.Scanner; Scanner java.util public class Main{
private static Scanner scanner;
public static void main(String args[]) {
	scanner = new Scanner(System.in);
	int a = scanner.nextInt();
	int[] b = new int[a];
	int count = 0;
	//int flag = 1;
	for(int i = 0;i < a;i++) {
		b[i] = scanner.nextInt();
	}
	for(int i = 0;i < a;i++) {
			for(int j = a-1;j >= 1;j--) {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		}
	}
	for(int i = 0;i < a;i++) {
		System.out.print(b[i]);
		if(i == a - 1) {
			System.out.println("");
		}else {
			System.out.print(" ");
		}
	}
	System.out.println(count);
}
} Main private static Scanner scanner; scanner public static void main(String args[]) {
	scanner = new Scanner(System.in);
	int a = scanner.nextInt();
	int[] b = new int[a];
	int count = 0;
	//int flag = 1;
	for(int i = 0;i < a;i++) {
		b[i] = scanner.nextInt();
	}
	for(int i = 0;i < a;i++) {
			for(int j = a-1;j >= 1;j--) {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		}
	}
	for(int i = 0;i < a;i++) {
		System.out.print(b[i]);
		if(i == a - 1) {
			System.out.println("");
		}else {
			System.out.print(" ");
		}
	}
	System.out.println(count);
} main {
	scanner = new Scanner(System.in);
	int a = scanner.nextInt();
	int[] b = new int[a];
	int count = 0;
	//int flag = 1;
	for(int i = 0;i < a;i++) {
		b[i] = scanner.nextInt();
	}
	for(int i = 0;i < a;i++) {
			for(int j = a-1;j >= 1;j--) {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		}
	}
	for(int i = 0;i < a;i++) {
		System.out.print(b[i]);
		if(i == a - 1) {
			System.out.println("");
		}else {
			System.out.print(" ");
		}
	}
	System.out.println(count);
} scanner = new Scanner(System.in) scanner new Scanner(System.in) int a = scanner.nextInt(); a scanner.nextInt() scanner.nextInt scanner int[] b = new int[a]; b new int[a] a int count = 0; count 0 for(int i = 0;i < a;i++) {
		b[i] = scanner.nextInt();
	} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
		b[i] = scanner.nextInt();
	} {
		b[i] = scanner.nextInt();
	} b[i] = scanner.nextInt() b[i] b i scanner.nextInt() scanner.nextInt scanner for(int i = 0;i < a;i++) {
			for(int j = a-1;j >= 1;j--) {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		}
	} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
			for(int j = a-1;j >= 1;j--) {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		}
	} {
			for(int j = a-1;j >= 1;j--) {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		}
	} for(int j = a-1;j >= 1;j--) {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		} int j = a-1; int j = a-1; j a-1 a 1 j >= 1 j 1 j-- j-- j {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		} {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		} if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			} b[j] < b[j-1] b[j] b j b[j-1] b j-1 j 1 {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			} int tmp = b[j]; tmp b[j] b j b[j] = b[j-1] b[j] b j b[j-1] b j-1 j 1 b[j-1] = tmp b[j-1] b j-1 j 1 tmp count++ count for(int i = 0;i < a;i++) {
		System.out.print(b[i]);
		if(i == a - 1) {
			System.out.println("");
		}else {
			System.out.print(" ");
		}
	} int i = 0; int i = 0; i 0 i < a i a i++ i++ i {
		System.out.print(b[i]);
		if(i == a - 1) {
			System.out.println("");
		}else {
			System.out.print(" ");
		}
	} {
		System.out.print(b[i]);
		if(i == a - 1) {
			System.out.println("");
		}else {
			System.out.print(" ");
		}
	} System.out.print(b[i]) System.out.print System.out System System.out b[i] b i if(i == a - 1) {
			System.out.println("");
		}else {
			System.out.print(" ");
		} i == a - 1 i a - 1 a 1 {
			System.out.println("");
		} System.out.println("") System.out.println System.out System System.out "" {
			System.out.print(" ");
		} System.out.print(" ") System.out.print System.out System System.out " " System.out.println(count) System.out.println System.out System System.out count String args[] args public class Main{
private static Scanner scanner;
public static void main(String args[]) {
	scanner = new Scanner(System.in);
	int a = scanner.nextInt();
	int[] b = new int[a];
	int count = 0;
	//int flag = 1;
	for(int i = 0;i < a;i++) {
		b[i] = scanner.nextInt();
	}
	for(int i = 0;i < a;i++) {
			for(int j = a-1;j >= 1;j--) {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		}
	}
	for(int i = 0;i < a;i++) {
		System.out.print(b[i]);
		if(i == a - 1) {
			System.out.println("");
		}else {
			System.out.print(" ");
		}
	}
	System.out.println(count);
}
} public class Main{
private static Scanner scanner;
public static void main(String args[]) {
	scanner = new Scanner(System.in);
	int a = scanner.nextInt();
	int[] b = new int[a];
	int count = 0;
	//int flag = 1;
	for(int i = 0;i < a;i++) {
		b[i] = scanner.nextInt();
	}
	for(int i = 0;i < a;i++) {
			for(int j = a-1;j >= 1;j--) {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		}
	}
	for(int i = 0;i < a;i++) {
		System.out.print(b[i]);
		if(i == a - 1) {
			System.out.println("");
		}else {
			System.out.print(" ");
		}
	}
	System.out.println(count);
}
} Main
import java.util.Scanner;
public class Main{
private static Scanner scanner;
public static void main(String args[]) {
	scanner = new Scanner(System.in);
	int a = scanner.nextInt();
	int[] b = new int[a];
	int count = 0;
	//int flag = 1;
	for(int i = 0;i < a;i++) {
		b[i] = scanner.nextInt();
	}
	for(int i = 0;i < a;i++) {
			for(int j = a-1;j >= 1;j--) {
				if(b[j] < b[j-1]) {
					int tmp = b[j];
					b[j] = b[j-1];
					b[j-1] = tmp;
					count++;
			}
		}
	}
	for(int i = 0;i < a;i++) {
		System.out.print(b[i]);
		if(i == a - 1) {
			System.out.println("");
		}else {
			System.out.print(" ");
		}
	}
	System.out.println(count);
}
}

