import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		String line2 = sc.nextLine();
		String[] k = line2.split(" ");
		for (int i = 0; i < v; i++) {
			vs[i] = Integer.parseInt(k[i]);
		}
		int i = 0;
		int count = 0;
		while(i<v-1){
			for (int j = v-1; j >-1; j--) {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			}i++;
		}
		
		for (int j = 0; j < v-1 ; j++) {
			System.out.print(vs[j]+" ");

		}
				System.out.println(vs[v-1]);
				System.out.println(count);



	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		String line2 = sc.nextLine();
		String[] k = line2.split(" ");
		for (int i = 0; i < v; i++) {
			vs[i] = Integer.parseInt(k[i]);
		}
		int i = 0;
		int count = 0;
		while(i<v-1){
			for (int j = v-1; j >-1; j--) {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			}i++;
		}
		
		for (int j = 0; j < v-1 ; j++) {
			System.out.print(vs[j]+" ");

		}
				System.out.println(vs[v-1]);
				System.out.println(count);



	}
} Main public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		String line2 = sc.nextLine();
		String[] k = line2.split(" ");
		for (int i = 0; i < v; i++) {
			vs[i] = Integer.parseInt(k[i]);
		}
		int i = 0;
		int count = 0;
		while(i<v-1){
			for (int j = v-1; j >-1; j--) {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			}i++;
		}
		
		for (int j = 0; j < v-1 ; j++) {
			System.out.print(vs[j]+" ");

		}
				System.out.println(vs[v-1]);
				System.out.println(count);



	} main {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		String line2 = sc.nextLine();
		String[] k = line2.split(" ");
		for (int i = 0; i < v; i++) {
			vs[i] = Integer.parseInt(k[i]);
		}
		int i = 0;
		int count = 0;
		while(i<v-1){
			for (int j = v-1; j >-1; j--) {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			}i++;
		}
		
		for (int j = 0; j < v-1 ; j++) {
			System.out.print(vs[j]+" ");

		}
				System.out.println(vs[v-1]);
				System.out.println(count);



	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc int v = Integer.parseInt(line); v Integer.parseInt(line) Integer.parseInt Integer line int[] vs = new int[v]; vs new int[v] v String line2 = sc.nextLine(); line2 sc.nextLine() sc.nextLine sc String[] k = line2.split(" "); k line2.split(" ") line2.split line2 " " for (int i = 0; i < v; i++) {
			vs[i] = Integer.parseInt(k[i]);
		} int i = 0; int i = 0; i 0 i < v i v i++ i++ i {
			vs[i] = Integer.parseInt(k[i]);
		} {
			vs[i] = Integer.parseInt(k[i]);
		} vs[i] = Integer.parseInt(k[i]) vs[i] vs i Integer.parseInt(k[i]) Integer.parseInt Integer k[i] k i int i = 0; i 0 int count = 0; count 0 while(i<v-1){
			for (int j = v-1; j >-1; j--) {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			}i++;
		} i<v-1 i v-1 v 1 {
			for (int j = v-1; j >-1; j--) {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			}i++;
		} for (int j = v-1; j >-1; j--) {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			} int j = v-1; int j = v-1; j v-1 v 1 j >-1 j -1 1 j-- j-- j {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			} {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			} int key=j-1; key j-1 j 1 if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				} vs[key]>vs[j] vs[key] vs key vs[j] vs j {
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				} int a=vs[key]; a vs[key] vs key int b = vs[j]; b vs[j] vs j vs[key]=b vs[key] vs key b vs[j]=a vs[j] vs j a count++ count key-- key if (key<0) {
					break;
				} key<0 key 0 {
					break;
				} break; i++ i for (int j = 0; j < v-1 ; j++) {
			System.out.print(vs[j]+" ");

		} int j = 0; int j = 0; j 0 j < v-1 j v-1 v 1 j++ j++ j {
			System.out.print(vs[j]+" ");

		} {
			System.out.print(vs[j]+" ");

		} System.out.print(vs[j]+" ") System.out.print System.out System System.out vs[j]+" " vs[j] vs j " " System.out.println(vs[v-1]) System.out.println System.out System System.out vs[v-1] vs v-1 v 1 System.out.println(count) System.out.println System.out System System.out count String[] arges arges public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		String line2 = sc.nextLine();
		String[] k = line2.split(" ");
		for (int i = 0; i < v; i++) {
			vs[i] = Integer.parseInt(k[i]);
		}
		int i = 0;
		int count = 0;
		while(i<v-1){
			for (int j = v-1; j >-1; j--) {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			}i++;
		}
		
		for (int j = 0; j < v-1 ; j++) {
			System.out.print(vs[j]+" ");

		}
				System.out.println(vs[v-1]);
				System.out.println(count);



	}
} public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		String line2 = sc.nextLine();
		String[] k = line2.split(" ");
		for (int i = 0; i < v; i++) {
			vs[i] = Integer.parseInt(k[i]);
		}
		int i = 0;
		int count = 0;
		while(i<v-1){
			for (int j = v-1; j >-1; j--) {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			}i++;
		}
		
		for (int j = 0; j < v-1 ; j++) {
			System.out.print(vs[j]+" ");

		}
				System.out.println(vs[v-1]);
				System.out.println(count);



	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] arges) {

		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		int v = Integer.parseInt(line);
		int[] vs = new int[v];
		String line2 = sc.nextLine();
		String[] k = line2.split(" ");
		for (int i = 0; i < v; i++) {
			vs[i] = Integer.parseInt(k[i]);
		}
		int i = 0;
		int count = 0;
		while(i<v-1){
			for (int j = v-1; j >-1; j--) {
				int key=j-1;
				if(vs[key]>vs[j]){
					int a=vs[key];
					int b = vs[j];
					vs[key]=b;
					vs[j]=a;
					count++;
				}key--;
				if (key<0) {
					break;
				}
			}i++;
		}
		
		for (int j = 0; j < v-1 ; j++) {
			System.out.print(vs[j]+" ");

		}
				System.out.println(vs[v-1]);
				System.out.println(count);



	}
}