import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int arrayIndex = 0; arrayIndex < n; arrayIndex++) {
			nums[arrayIndex] = sc.nextInt();
		}
		boolean flag = true;
		int swapCount = 0;
		while(flag) {
			flag = false;
			for(int j = n - 1; j > 0; j--) {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			}
		}
		printArray(nums);
		System.out.println(swapCount);
	}
	public static void printArray(int[] array) {
		int arrayLength = array.length;
		for(int index = 0; index < arrayLength - 1; index++) {
			System.out.print(array[index] + " ");
		}
		System.out.println(array[arrayLength - 1]);
	}
} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int arrayIndex = 0; arrayIndex < n; arrayIndex++) {
			nums[arrayIndex] = sc.nextInt();
		}
		boolean flag = true;
		int swapCount = 0;
		while(flag) {
			flag = false;
			for(int j = n - 1; j > 0; j--) {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			}
		}
		printArray(nums);
		System.out.println(swapCount);
	}
	public static void printArray(int[] array) {
		int arrayLength = array.length;
		for(int index = 0; index < arrayLength - 1; index++) {
			System.out.print(array[index] + " ");
		}
		System.out.println(array[arrayLength - 1]);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int arrayIndex = 0; arrayIndex < n; arrayIndex++) {
			nums[arrayIndex] = sc.nextInt();
		}
		boolean flag = true;
		int swapCount = 0;
		while(flag) {
			flag = false;
			for(int j = n - 1; j > 0; j--) {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			}
		}
		printArray(nums);
		System.out.println(swapCount);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int arrayIndex = 0; arrayIndex < n; arrayIndex++) {
			nums[arrayIndex] = sc.nextInt();
		}
		boolean flag = true;
		int swapCount = 0;
		while(flag) {
			flag = false;
			for(int j = n - 1; j > 0; j--) {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			}
		}
		printArray(nums);
		System.out.println(swapCount);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] nums = new int[n]; nums new int[n] n for(int arrayIndex = 0; arrayIndex < n; arrayIndex++) {
			nums[arrayIndex] = sc.nextInt();
		} int arrayIndex = 0; int arrayIndex = 0; arrayIndex 0 arrayIndex < n arrayIndex n arrayIndex++ arrayIndex++ arrayIndex {
			nums[arrayIndex] = sc.nextInt();
		} {
			nums[arrayIndex] = sc.nextInt();
		} nums[arrayIndex] = sc.nextInt() nums[arrayIndex] nums arrayIndex sc.nextInt() sc.nextInt sc boolean flag = true; flag true int swapCount = 0; swapCount 0 while(flag) {
			flag = false;
			for(int j = n - 1; j > 0; j--) {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			}
		} flag {
			flag = false;
			for(int j = n - 1; j > 0; j--) {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			}
		} flag = false flag false for(int j = n - 1; j > 0; j--) {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			} int j = n - 1; int j = n - 1; j n - 1 n 1 j > 0 j 0 j-- j-- j {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			} {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			} if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				} nums[j] < nums[j - 1] nums[j] nums j nums[j - 1] nums j - 1 j 1 {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				} int work = nums[j]; work nums[j] nums j nums[j] = nums[j - 1] nums[j] nums j nums[j - 1] nums j - 1 j 1 nums[j - 1] = work nums[j - 1] nums j - 1 j 1 work flag = true flag true swapCount++ swapCount printArray(nums) printArray nums System.out.println(swapCount) System.out.println System.out System System.out swapCount String[] args args public static void printArray(int[] array) {
		int arrayLength = array.length;
		for(int index = 0; index < arrayLength - 1; index++) {
			System.out.print(array[index] + " ");
		}
		System.out.println(array[arrayLength - 1]);
	} printArray {
		int arrayLength = array.length;
		for(int index = 0; index < arrayLength - 1; index++) {
			System.out.print(array[index] + " ");
		}
		System.out.println(array[arrayLength - 1]);
	} int arrayLength = array.length; arrayLength array.length array array.length for(int index = 0; index < arrayLength - 1; index++) {
			System.out.print(array[index] + " ");
		} int index = 0; int index = 0; index 0 index < arrayLength - 1 index arrayLength - 1 arrayLength 1 index++ index++ index {
			System.out.print(array[index] + " ");
		} {
			System.out.print(array[index] + " ");
		} System.out.print(array[index] + " ") System.out.print System.out System System.out array[index] + " " array[index] array index " " System.out.println(array[arrayLength - 1]) System.out.println System.out System System.out array[arrayLength - 1] array arrayLength - 1 arrayLength 1 int[] array array public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int arrayIndex = 0; arrayIndex < n; arrayIndex++) {
			nums[arrayIndex] = sc.nextInt();
		}
		boolean flag = true;
		int swapCount = 0;
		while(flag) {
			flag = false;
			for(int j = n - 1; j > 0; j--) {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			}
		}
		printArray(nums);
		System.out.println(swapCount);
	}
	public static void printArray(int[] array) {
		int arrayLength = array.length;
		for(int index = 0; index < arrayLength - 1; index++) {
			System.out.print(array[index] + " ");
		}
		System.out.println(array[arrayLength - 1]);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int arrayIndex = 0; arrayIndex < n; arrayIndex++) {
			nums[arrayIndex] = sc.nextInt();
		}
		boolean flag = true;
		int swapCount = 0;
		while(flag) {
			flag = false;
			for(int j = n - 1; j > 0; j--) {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			}
		}
		printArray(nums);
		System.out.println(swapCount);
	}
	public static void printArray(int[] array) {
		int arrayLength = array.length;
		for(int index = 0; index < arrayLength - 1; index++) {
			System.out.print(array[index] + " ");
		}
		System.out.println(array[arrayLength - 1]);
	}
} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int arrayIndex = 0; arrayIndex < n; arrayIndex++) {
			nums[arrayIndex] = sc.nextInt();
		}
		boolean flag = true;
		int swapCount = 0;
		while(flag) {
			flag = false;
			for(int j = n - 1; j > 0; j--) {
				if(nums[j] < nums[j - 1]) {
					int work = nums[j];
					nums[j] = nums[j - 1];
					nums[j - 1] = work;
					flag = true;
					swapCount++;
				}
			}
		}
		printArray(nums);
		System.out.println(swapCount);
	}
	public static void printArray(int[] array) {
		int arrayLength = array.length;
		for(int index = 0; index < arrayLength - 1; index++) {
			System.out.print(array[index] + " ");
		}
		System.out.println(array[arrayLength - 1]);
	}
}