import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] arr = new int[num];
		int count = 0;
		
		for (int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		boolean sorted = false;
		while (!sorted) {
			sorted = true;
			for (int i = 0; i < num - 1; i++) {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			}
		}
		
		for (int i = 0; i < num; i++) {
			System.out.print(arr[i]);
			if (i != num - 1)
				System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] arr = new int[num];
		int count = 0;
		
		for (int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		boolean sorted = false;
		while (!sorted) {
			sorted = true;
			for (int i = 0; i < num - 1; i++) {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			}
		}
		
		for (int i = 0; i < num; i++) {
			System.out.print(arr[i]);
			if (i != num - 1)
				System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] arr = new int[num];
		int count = 0;
		
		for (int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		boolean sorted = false;
		while (!sorted) {
			sorted = true;
			for (int i = 0; i < num - 1; i++) {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			}
		}
		
		for (int i = 0; i < num; i++) {
			System.out.print(arr[i]);
			if (i != num - 1)
				System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] arr = new int[num];
		int count = 0;
		
		for (int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		boolean sorted = false;
		while (!sorted) {
			sorted = true;
			for (int i = 0; i < num - 1; i++) {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			}
		}
		
		for (int i = 0; i < num; i++) {
			System.out.print(arr[i]);
			if (i != num - 1)
				System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int num = sc.nextInt(); num sc.nextInt() sc.nextInt sc int[] arr = new int[num]; arr new int[num] num int count = 0; count 0 for (int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			arr[i] = sc.nextInt();
		} {
			arr[i] = sc.nextInt();
		} arr[i] = sc.nextInt() arr[i] arr i sc.nextInt() sc.nextInt sc boolean sorted = false; sorted false while (!sorted) {
			sorted = true;
			for (int i = 0; i < num - 1; i++) {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			}
		} !sorted sorted {
			sorted = true;
			for (int i = 0; i < num - 1; i++) {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			}
		} sorted = true sorted true for (int i = 0; i < num - 1; i++) {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			} int i = 0; int i = 0; i 0 i < num - 1 i num - 1 num 1 i++ i++ i {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			} {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			} if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				} arr[i + 1] < arr[i] arr[i + 1] arr i + 1 i 1 arr[i] arr i {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				} int temp = arr[i]; temp arr[i] arr i arr[i] = arr[i + 1] arr[i] arr i arr[i + 1] arr i + 1 i 1 arr[i + 1] = temp arr[i + 1] arr i + 1 i 1 temp count++ count sorted = false sorted false for (int i = 0; i < num; i++) {
			System.out.print(arr[i]);
			if (i != num - 1)
				System.out.print(" ");
		} int i = 0; int i = 0; i 0 i < num i num i++ i++ i {
			System.out.print(arr[i]);
			if (i != num - 1)
				System.out.print(" ");
		} {
			System.out.print(arr[i]);
			if (i != num - 1)
				System.out.print(" ");
		} System.out.print(arr[i]) System.out.print System.out System System.out arr[i] arr i if (i != num - 1)
				System.out.print(" "); i != num - 1 i num - 1 num 1 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 String[] args args public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] arr = new int[num];
		int count = 0;
		
		for (int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		boolean sorted = false;
		while (!sorted) {
			sorted = true;
			for (int i = 0; i < num - 1; i++) {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			}
		}
		
		for (int i = 0; i < num; i++) {
			System.out.print(arr[i]);
			if (i != num - 1)
				System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] arr = new int[num];
		int count = 0;
		
		for (int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		boolean sorted = false;
		while (!sorted) {
			sorted = true;
			for (int i = 0; i < num - 1; i++) {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			}
		}
		
		for (int i = 0; i < num; i++) {
			System.out.print(arr[i]);
			if (i != num - 1)
				System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		int[] arr = new int[num];
		int count = 0;
		
		for (int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		boolean sorted = false;
		while (!sorted) {
			sorted = true;
			for (int i = 0; i < num - 1; i++) {
				if (arr[i + 1] < arr[i]) {
					int temp = arr[i];
					arr[i] = arr[i + 1];
					arr[i + 1] = temp;
					count++;
					sorted = false;
				}
			}
		}
		
		for (int i = 0; i < num; i++) {
			System.out.print(arr[i]);
			if (i != num - 1)
				System.out.print(" ");
		}
		System.out.println("");
		System.out.println(count);
	}
}