import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];
    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	int count = 0;
    	for (int i = 0; i < n; i++) {
    		for (int j = n - 1; j > i; j--) {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		}
    	}

    	printData(data);
    	System.out.println(count);

        sc.close();
	}

	private static void printData(int[] data) {
		StringBuffer printData = new StringBuffer();
		for (int i = 0; i < data.length; i++) {
			printData.append(data[i]);
			printData.append(" ");
		}
		printData.delete(printData.length() - 1, printData.length());
		System.out.println(printData);
	}
} 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[] data = new int[n];
    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	int count = 0;
    	for (int i = 0; i < n; i++) {
    		for (int j = n - 1; j > i; j--) {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		}
    	}

    	printData(data);
    	System.out.println(count);

        sc.close();
	}

	private static void printData(int[] data) {
		StringBuffer printData = new StringBuffer();
		for (int i = 0; i < data.length; i++) {
			printData.append(data[i]);
			printData.append(" ");
		}
		printData.delete(printData.length() - 1, printData.length());
		System.out.println(printData);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];
    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	int count = 0;
    	for (int i = 0; i < n; i++) {
    		for (int j = n - 1; j > i; j--) {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		}
    	}

    	printData(data);
    	System.out.println(count);

        sc.close();
	} main {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];
    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	int count = 0;
    	for (int i = 0; i < n; i++) {
    		for (int j = n - 1; j > i; j--) {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		}
    	}

    	printData(data);
    	System.out.println(count);

        sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] data = new int[n]; data new int[n] n for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
    		data[i] = sc.nextInt();
    	} {
    		data[i] = sc.nextInt();
    	} data[i] = sc.nextInt() data[i] data i sc.nextInt() sc.nextInt sc int count = 0; count 0 for (int i = 0; i < n; i++) {
    		for (int j = n - 1; j > i; j--) {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		}
    	} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
    		for (int j = n - 1; j > i; j--) {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		}
    	} {
    		for (int j = n - 1; j > i; j--) {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		}
    	} for (int j = n - 1; j > i; j--) {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		} int j = n - 1; int j = n - 1; j n - 1 n 1 j > i j i j-- j-- j {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		} {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		} if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			} data[j] < data[j - 1] data[j] data j data[j - 1] data j - 1 j 1 {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			} int temp = data[j]; temp data[j] data j data[j] = data[j - 1] data[j] data j data[j - 1] data j - 1 j 1 data[j - 1] = temp data[j - 1] data j - 1 j 1 temp count++ count printData(data) printData data System.out.println(count) System.out.println System.out System System.out count sc.close() sc.close sc String[] args args private static void printData(int[] data) {
		StringBuffer printData = new StringBuffer();
		for (int i = 0; i < data.length; i++) {
			printData.append(data[i]);
			printData.append(" ");
		}
		printData.delete(printData.length() - 1, printData.length());
		System.out.println(printData);
	} printData {
		StringBuffer printData = new StringBuffer();
		for (int i = 0; i < data.length; i++) {
			printData.append(data[i]);
			printData.append(" ");
		}
		printData.delete(printData.length() - 1, printData.length());
		System.out.println(printData);
	} StringBuffer printData = new StringBuffer(); printData new StringBuffer() for (int i = 0; i < data.length; i++) {
			printData.append(data[i]);
			printData.append(" ");
		} int i = 0; int i = 0; i 0 i < data.length i data.length data data.length i++ i++ i {
			printData.append(data[i]);
			printData.append(" ");
		} {
			printData.append(data[i]);
			printData.append(" ");
		} printData.append(data[i]) printData.append printData data[i] data i printData.append(" ") printData.append printData " " printData.delete(printData.length() - 1, printData.length()) printData.delete printData printData.length() - 1 printData.length() printData.length printData 1 printData.length() printData.length printData System.out.println(printData) System.out.println System.out System System.out printData int[] data data public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];
    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	int count = 0;
    	for (int i = 0; i < n; i++) {
    		for (int j = n - 1; j > i; j--) {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		}
    	}

    	printData(data);
    	System.out.println(count);

        sc.close();
	}

	private static void printData(int[] data) {
		StringBuffer printData = new StringBuffer();
		for (int i = 0; i < data.length; i++) {
			printData.append(data[i]);
			printData.append(" ");
		}
		printData.delete(printData.length() - 1, printData.length());
		System.out.println(printData);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in); 

		int n = sc.nextInt();
		int[] data = new int[n];
    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	int count = 0;
    	for (int i = 0; i < n; i++) {
    		for (int j = n - 1; j > i; j--) {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		}
    	}

    	printData(data);
    	System.out.println(count);

        sc.close();
	}

	private static void printData(int[] data) {
		StringBuffer printData = new StringBuffer();
		for (int i = 0; i < data.length; i++) {
			printData.append(data[i]);
			printData.append(" ");
		}
		printData.delete(printData.length() - 1, printData.length());
		System.out.println(printData);
	}
} 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[] data = new int[n];
    	for (int i = 0; i < n; i++) {
    		data[i] = sc.nextInt();
    	}

    	int count = 0;
    	for (int i = 0; i < n; i++) {
    		for (int j = n - 1; j > i; j--) {
    			if (data[j] < data[j - 1]) {
    				int temp = data[j];
    				data[j] = data[j - 1];
    				data[j - 1] = temp;
    				count++;
    			}
    		}
    	}

    	printData(data);
    	System.out.println(count);

        sc.close();
	}

	private static void printData(int[] data) {
		StringBuffer printData = new StringBuffer();
		for (int i = 0; i < data.length; i++) {
			printData.append(data[i]);
			printData.append(" ");
		}
		printData.delete(printData.length() - 1, printData.length());
		System.out.println(printData);
	}
}