

import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		bubbleSort(A, N);
		scan.close();
	}

	public static void bubbleSort(int[] A, int N) {
		// ???????????°
		int count = 0;
		boolean flag = true;
		int i = 0;
		while(flag){
			flag = false;
			for (int j = N - 1; j > i; j--) {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			}
			i++;
		}
		String output = Arrays.toString(A).replaceAll(",", "");
		System.out.println(output.substring(1, output.length() - 1));
		System.out.println(count);
	}
} import java.util.Arrays; Arrays 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();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		bubbleSort(A, N);
		scan.close();
	}

	public static void bubbleSort(int[] A, int N) {
		// ???????????°
		int count = 0;
		boolean flag = true;
		int i = 0;
		while(flag){
			flag = false;
			for (int j = N - 1; j > i; j--) {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			}
			i++;
		}
		String output = Arrays.toString(A).replaceAll(",", "");
		System.out.println(output.substring(1, output.length() - 1));
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		bubbleSort(A, N);
		scan.close();
	} main {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		bubbleSort(A, N);
		scan.close();
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int N = scan.nextInt(); N scan.nextInt() scan.nextInt scan int[] A = new int[N]; A new int[N] N for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			A[i] = scan.nextInt();
		} {
			A[i] = scan.nextInt();
		} A[i] = scan.nextInt() A[i] A i scan.nextInt() scan.nextInt scan bubbleSort(A, N) bubbleSort A N scan.close() scan.close scan String[] args args public static void bubbleSort(int[] A, int N) {
		// ???????????°
		int count = 0;
		boolean flag = true;
		int i = 0;
		while(flag){
			flag = false;
			for (int j = N - 1; j > i; j--) {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			}
			i++;
		}
		String output = Arrays.toString(A).replaceAll(",", "");
		System.out.println(output.substring(1, output.length() - 1));
		System.out.println(count);
	} bubbleSort {
		// ???????????°
		int count = 0;
		boolean flag = true;
		int i = 0;
		while(flag){
			flag = false;
			for (int j = N - 1; j > i; j--) {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			}
			i++;
		}
		String output = Arrays.toString(A).replaceAll(",", "");
		System.out.println(output.substring(1, output.length() - 1));
		System.out.println(count);
	} int count = 0; count 0 boolean flag = true; flag true int i = 0; i 0 while(flag){
			flag = false;
			for (int j = N - 1; j > i; j--) {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			}
			i++;
		} flag {
			flag = false;
			for (int j = N - 1; j > i; j--) {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			}
			i++;
		} flag = false flag false for (int j = N - 1; j > i; j--) {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			} int j = N - 1; int j = N - 1; j N - 1 N 1 j > i j i j-- j-- j {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			} {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			} if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				} A[j] < A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				} int temp = A[j]; temp A[j] A j A[j] = A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 A[j - 1] = temp A[j - 1] A j - 1 j 1 temp flag = true flag true count++ count i++ i String output = Arrays.toString(A).replaceAll(",", ""); output Arrays.toString(A).replaceAll(",", "") Arrays.toString(A).replaceAll Arrays.toString(A) Arrays.toString Arrays A "," "" System.out.println(output.substring(1, output.length() - 1)) System.out.println System.out System System.out output.substring(1, output.length() - 1) output.substring output 1 output.length() - 1 output.length() output.length output 1 System.out.println(count) System.out.println System.out System System.out count int[] A A int N N public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		bubbleSort(A, N);
		scan.close();
	}

	public static void bubbleSort(int[] A, int N) {
		// ???????????°
		int count = 0;
		boolean flag = true;
		int i = 0;
		while(flag){
			flag = false;
			for (int j = N - 1; j > i; j--) {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			}
			i++;
		}
		String output = Arrays.toString(A).replaceAll(",", "");
		System.out.println(output.substring(1, output.length() - 1));
		System.out.println(count);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		bubbleSort(A, N);
		scan.close();
	}

	public static void bubbleSort(int[] A, int N) {
		// ???????????°
		int count = 0;
		boolean flag = true;
		int i = 0;
		while(flag){
			flag = false;
			for (int j = N - 1; j > i; j--) {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			}
			i++;
		}
		String output = Arrays.toString(A).replaceAll(",", "");
		System.out.println(output.substring(1, output.length() - 1));
		System.out.println(count);
	}
} Main


import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = scan.nextInt();
		}
		bubbleSort(A, N);
		scan.close();
	}

	public static void bubbleSort(int[] A, int N) {
		// ???????????°
		int count = 0;
		boolean flag = true;
		int i = 0;
		while(flag){
			flag = false;
			for (int j = N - 1; j > i; j--) {
				if (A[j] < A[j - 1]) {
					int temp = A[j];
					A[j] = A[j - 1];
					A[j - 1] = temp;
					flag = true;
					count++;
				}
			}
			i++;
		}
		String output = Arrays.toString(A).replaceAll(",", "");
		System.out.println(output.substring(1, output.length() - 1));
		System.out.println(count);
	}
}