import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		bubbleSort(list);
	}

	public static void bubbleSort(List<Integer> list) {
		int count = 0;
		for (int i = 1; i < list.size(); i++) {
			int j = i - 1;
			while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			}
		}
		showList(list);
		System.out.println(count);
	}

	public static void showList(List<Integer> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			System.out.print(list.get(i));
			System.out.print(" ");
		}
		System.out.println(list.get(list.size() - 1));
	}
}
 import java.util.ArrayList; ArrayList java.util import java.util.List; List java.util import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		bubbleSort(list);
	}

	public static void bubbleSort(List<Integer> list) {
		int count = 0;
		for (int i = 1; i < list.size(); i++) {
			int j = i - 1;
			while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			}
		}
		showList(list);
		System.out.println(count);
	}

	public static void showList(List<Integer> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			System.out.print(list.get(i));
			System.out.print(" ");
		}
		System.out.println(list.get(list.size() - 1));
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		bubbleSort(list);
	} main {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		bubbleSort(list);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan List<Integer> list = new ArrayList<Integer>(); list new ArrayList<Integer>() for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			list.add(scan.nextInt());
		} {
			list.add(scan.nextInt());
		} list.add(scan.nextInt()) list.add list scan.nextInt() scan.nextInt scan bubbleSort(list) bubbleSort list String[] args args public static void bubbleSort(List<Integer> list) {
		int count = 0;
		for (int i = 1; i < list.size(); i++) {
			int j = i - 1;
			while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			}
		}
		showList(list);
		System.out.println(count);
	} bubbleSort {
		int count = 0;
		for (int i = 1; i < list.size(); i++) {
			int j = i - 1;
			while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			}
		}
		showList(list);
		System.out.println(count);
	} int count = 0; count 0 for (int i = 1; i < list.size(); i++) {
			int j = i - 1;
			while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			}
		} int i = 1; int i = 1; i 1 i < list.size() i list.size() list.size list i++ i++ i {
			int j = i - 1;
			while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			}
		} {
			int j = i - 1;
			while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			}
		} int j = i - 1; j i - 1 i 1 while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			} j >= 0 && list.get(j + 1) < list.get(j) j >= 0 j 0 list.get(j + 1) < list.get(j) list.get(j + 1) list.get list j + 1 j 1 list.get(j) list.get list j {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			} int tmp = list.get(j + 1); tmp list.get(j + 1) list.get list j + 1 j 1 list.set(j + 1, list.get(j)) list.set list j + 1 j 1 list.get(j) list.get list j list.set(j, tmp) list.set list j tmp j-- j count++ count showList(list) showList list System.out.println(count) System.out.println System.out System System.out count List<Integer> list list public static void showList(List<Integer> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			System.out.print(list.get(i));
			System.out.print(" ");
		}
		System.out.println(list.get(list.size() - 1));
	} showList {
		for (int i = 0; i < list.size() - 1; i++) {
			System.out.print(list.get(i));
			System.out.print(" ");
		}
		System.out.println(list.get(list.size() - 1));
	} for (int i = 0; i < list.size() - 1; i++) {
			System.out.print(list.get(i));
			System.out.print(" ");
		} int i = 0; int i = 0; i 0 i < list.size() - 1 i list.size() - 1 list.size() list.size list 1 i++ i++ i {
			System.out.print(list.get(i));
			System.out.print(" ");
		} {
			System.out.print(list.get(i));
			System.out.print(" ");
		} System.out.print(list.get(i)) System.out.print System.out System System.out list.get(i) list.get list i System.out.print(" ") System.out.print System.out System System.out " " System.out.println(list.get(list.size() - 1)) System.out.println System.out System System.out list.get(list.size() - 1) list.get list list.size() - 1 list.size() list.size list 1 List<Integer> list list public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		bubbleSort(list);
	}

	public static void bubbleSort(List<Integer> list) {
		int count = 0;
		for (int i = 1; i < list.size(); i++) {
			int j = i - 1;
			while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			}
		}
		showList(list);
		System.out.println(count);
	}

	public static void showList(List<Integer> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			System.out.print(list.get(i));
			System.out.print(" ");
		}
		System.out.println(list.get(list.size() - 1));
	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		bubbleSort(list);
	}

	public static void bubbleSort(List<Integer> list) {
		int count = 0;
		for (int i = 1; i < list.size(); i++) {
			int j = i - 1;
			while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			}
		}
		showList(list);
		System.out.println(count);
	}

	public static void showList(List<Integer> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			System.out.print(list.get(i));
			System.out.print(" ");
		}
		System.out.println(list.get(list.size() - 1));
	}
} Main
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for (int i = 0; i < N; i++) {
			list.add(scan.nextInt());
		}
		bubbleSort(list);
	}

	public static void bubbleSort(List<Integer> list) {
		int count = 0;
		for (int i = 1; i < list.size(); i++) {
			int j = i - 1;
			while (j >= 0 && list.get(j + 1) < list.get(j)) {
				int tmp = list.get(j + 1);
				list.set(j + 1, list.get(j));
				list.set(j, tmp);
				j--;
				count++;
			}
		}
		showList(list);
		System.out.println(count);
	}

	public static void showList(List<Integer> list) {
		for (int i = 0; i < list.size() - 1; i++) {
			System.out.print(list.get(i));
			System.out.print(" ");
		}
		System.out.println(list.get(list.size() - 1));
	}
}

