import java.util.Scanner;

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

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		int n = scanner.nextInt();
		
		int a[] = new int[n];
		
		for (int i = 0; i < n; i++) {
			a[i] = scanner.nextInt();
		}
		
		boolean flag = true;
		int count = 0;
		int j = 0;
		
		while(flag) {
			flag = false;
			for (int i = n - 1; i >= j + 1; i--) {
				if (a[i] < a[i - 1]) {
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;
					flag = true;
					count++;
				}
			}
			j++;
		}
		
		for (int i = 0; i < n-1; i++) {
			System.out.print(a[i] + " ");
		}
		System.out.println(a[n - 1]);
		
		System.out.println(count);
	}
} 

