import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		int nums[] = new int[len];
		int counts = 0;

		for (int i = 0; i < len; i++) {
			nums[i] = scanner.nextInt();
		}
		int flag = 1;
		while (flag == 1) {
			flag = 0;
			if (nums.length > 1) {
				for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				}
			}
		}

		new Main().arrayToString(nums);
		System.out.println(counts);
	}

	public void arrayToString(int[] arr) {
		for (int i = 0; i < arr.length; i++) {

			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		}
	}

} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		int nums[] = new int[len];
		int counts = 0;

		for (int i = 0; i < len; i++) {
			nums[i] = scanner.nextInt();
		}
		int flag = 1;
		while (flag == 1) {
			flag = 0;
			if (nums.length > 1) {
				for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				}
			}
		}

		new Main().arrayToString(nums);
		System.out.println(counts);
	}

	public void arrayToString(int[] arr) {
		for (int i = 0; i < arr.length; i++) {

			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		}
	}

} Main public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		int nums[] = new int[len];
		int counts = 0;

		for (int i = 0; i < len; i++) {
			nums[i] = scanner.nextInt();
		}
		int flag = 1;
		while (flag == 1) {
			flag = 0;
			if (nums.length > 1) {
				for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				}
			}
		}

		new Main().arrayToString(nums);
		System.out.println(counts);
	} main {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		int nums[] = new int[len];
		int counts = 0;

		for (int i = 0; i < len; i++) {
			nums[i] = scanner.nextInt();
		}
		int flag = 1;
		while (flag == 1) {
			flag = 0;
			if (nums.length > 1) {
				for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				}
			}
		}

		new Main().arrayToString(nums);
		System.out.println(counts);
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int len = scanner.nextInt(); len scanner.nextInt() scanner.nextInt scanner int nums[] = new int[len]; nums new int[len] len int counts = 0; counts 0 for (int i = 0; i < len; i++) {
			nums[i] = scanner.nextInt();
		} int i = 0; int i = 0; i 0 i < len i len i++ i++ i {
			nums[i] = scanner.nextInt();
		} {
			nums[i] = scanner.nextInt();
		} nums[i] = scanner.nextInt() nums[i] nums i scanner.nextInt() scanner.nextInt scanner int flag = 1; flag 1 while (flag == 1) {
			flag = 0;
			if (nums.length > 1) {
				for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				}
			}
		} flag == 1 flag 1 {
			flag = 0;
			if (nums.length > 1) {
				for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				}
			}
		} flag = 0 flag 0 if (nums.length > 1) {
				for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				}
			} nums.length > 1 nums.length nums nums.length 1 {
				for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				}
			} for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				} int i = 1; int i = 1; i 1 i < nums.length i nums.length nums nums.length i++ i++ i {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				} {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				} if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					} nums[i-1] > nums[i] nums[i-1] nums i-1 i 1 nums[i] nums i {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					} int tmp = nums[i-1]; tmp nums[i-1] nums i-1 i 1 nums[i-1] = nums[i] nums[i-1] nums i-1 i 1 nums[i] nums i nums[i] = tmp nums[i] nums i tmp flag = 1 flag 1 counts++ counts new Main().arrayToString(nums) new Main().arrayToString new Main() nums System.out.println(counts) System.out.println System.out System System.out counts String[] args args public void arrayToString(int[] arr) {
		for (int i = 0; i < arr.length; i++) {

			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		}
	} arrayToString {
		for (int i = 0; i < arr.length; i++) {

			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		}
	} for (int i = 0; i < arr.length; i++) {

			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		} int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i {

			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		} {

			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		} if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			} i == arr.length - 1 i arr.length - 1 arr.length arr arr.length 1 {
				System.out.println(arr[i]);
			} System.out.println(arr[i]) System.out.println System.out System System.out arr[i] arr i {
				System.out.print(arr[i] + " ");
			} System.out.print(arr[i] + " ") System.out.print System.out System System.out arr[i] + " " arr[i] arr i " " int[] arr arr public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		int nums[] = new int[len];
		int counts = 0;

		for (int i = 0; i < len; i++) {
			nums[i] = scanner.nextInt();
		}
		int flag = 1;
		while (flag == 1) {
			flag = 0;
			if (nums.length > 1) {
				for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				}
			}
		}

		new Main().arrayToString(nums);
		System.out.println(counts);
	}

	public void arrayToString(int[] arr) {
		for (int i = 0; i < arr.length; i++) {

			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		}
	}

} public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		int nums[] = new int[len];
		int counts = 0;

		for (int i = 0; i < len; i++) {
			nums[i] = scanner.nextInt();
		}
		int flag = 1;
		while (flag == 1) {
			flag = 0;
			if (nums.length > 1) {
				for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				}
			}
		}

		new Main().arrayToString(nums);
		System.out.println(counts);
	}

	public void arrayToString(int[] arr) {
		for (int i = 0; i < arr.length; i++) {

			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		}
	}

} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int len = scanner.nextInt();
		int nums[] = new int[len];
		int counts = 0;

		for (int i = 0; i < len; i++) {
			nums[i] = scanner.nextInt();
		}
		int flag = 1;
		while (flag == 1) {
			flag = 0;
			if (nums.length > 1) {
				for (int i = 1; i < nums.length; i++) {
					if (nums[i-1] > nums[i]) {
						int tmp = nums[i-1];
						nums[i-1] = nums[i];
						nums[i] = tmp;
						flag = 1;
						counts++;
					}
				}
			}
		}

		new Main().arrayToString(nums);
		System.out.println(counts);
	}

	public void arrayToString(int[] arr) {
		for (int i = 0; i < arr.length; i++) {

			if (i == arr.length - 1) {
				System.out.println(arr[i]);
			} else {
				System.out.print(arr[i] + " ");
			}
		}
	}

}
