import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] num = new int[n];
		for (int i=0; i<n; i++) {
			num[i]=scn.nextInt();
		}
		int tmp;
		int count=0;
		for(int i=0; i<num.length-1; i++) {
			for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int a=0;a<num.length-1;a++ ) {
			sb.append(num[a]+" ");
		}
		System.out.println(sb.append(num[num.length-1]).toString());
		System.out.println(count);

	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] num = new int[n];
		for (int i=0; i<n; i++) {
			num[i]=scn.nextInt();
		}
		int tmp;
		int count=0;
		for(int i=0; i<num.length-1; i++) {
			for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int a=0;a<num.length-1;a++ ) {
			sb.append(num[a]+" ");
		}
		System.out.println(sb.append(num[num.length-1]).toString());
		System.out.println(count);

	}
} Main public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] num = new int[n];
		for (int i=0; i<n; i++) {
			num[i]=scn.nextInt();
		}
		int tmp;
		int count=0;
		for(int i=0; i<num.length-1; i++) {
			for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int a=0;a<num.length-1;a++ ) {
			sb.append(num[a]+" ");
		}
		System.out.println(sb.append(num[num.length-1]).toString());
		System.out.println(count);

	} main {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] num = new int[n];
		for (int i=0; i<n; i++) {
			num[i]=scn.nextInt();
		}
		int tmp;
		int count=0;
		for(int i=0; i<num.length-1; i++) {
			for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int a=0;a<num.length-1;a++ ) {
			sb.append(num[a]+" ");
		}
		System.out.println(sb.append(num[num.length-1]).toString());
		System.out.println(count);

	} Scanner scn = new Scanner(System.in); scn new Scanner(System.in) int n = scn.nextInt(); n scn.nextInt() scn.nextInt scn int[] num = new int[n]; num new int[n] n for (int i=0; i<n; i++) {
			num[i]=scn.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			num[i]=scn.nextInt();
		} {
			num[i]=scn.nextInt();
		} num[i]=scn.nextInt() num[i] num i scn.nextInt() scn.nextInt scn int tmp; tmp int count=0; count 0 for(int i=0; i<num.length-1; i++) {
			for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			}
		} int i=0; int i=0; i 0 i<num.length-1 i num.length-1 num.length num num.length 1 i++ i++ i {
			for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			}
		} {
			for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			}
		} for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			} int j = num.length-1; int j = num.length-1; j num.length-1 num.length num num.length 1 j>i j i j-- j-- j {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			} {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			} if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				} num[j-1]>num[j] num[j-1] num j-1 j 1 num[j] num j {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				} tmp=num[j] tmp num[j] num j num[j]=num[j-1] num[j] num j num[j-1] num j-1 j 1 num[j-1]=tmp num[j-1] num j-1 j 1 tmp count++ count StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int a=0;a<num.length-1;a++ ) {
			sb.append(num[a]+" ");
		} int a=0; int a=0; a 0 a<num.length-1 a num.length-1 num.length num num.length 1 a++ a++ a {
			sb.append(num[a]+" ");
		} {
			sb.append(num[a]+" ");
		} sb.append(num[a]+" ") sb.append sb num[a]+" " num[a] num a " " System.out.println(sb.append(num[num.length-1]).toString()) System.out.println System.out System System.out sb.append(num[num.length-1]).toString() sb.append(num[num.length-1]).toString sb.append(num[num.length-1]) sb.append sb num[num.length-1] num num.length-1 num.length num num.length 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] num = new int[n];
		for (int i=0; i<n; i++) {
			num[i]=scn.nextInt();
		}
		int tmp;
		int count=0;
		for(int i=0; i<num.length-1; i++) {
			for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int a=0;a<num.length-1;a++ ) {
			sb.append(num[a]+" ");
		}
		System.out.println(sb.append(num[num.length-1]).toString());
		System.out.println(count);

	}
} public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] num = new int[n];
		for (int i=0; i<n; i++) {
			num[i]=scn.nextInt();
		}
		int tmp;
		int count=0;
		for(int i=0; i<num.length-1; i++) {
			for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int a=0;a<num.length-1;a++ ) {
			sb.append(num[a]+" ");
		}
		System.out.println(sb.append(num[num.length-1]).toString());
		System.out.println(count);

	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int n = scn.nextInt();
		int[] num = new int[n];
		for (int i=0; i<n; i++) {
			num[i]=scn.nextInt();
		}
		int tmp;
		int count=0;
		for(int i=0; i<num.length-1; i++) {
			for(int j = num.length-1;j>i;j--) {
				if(num[j-1]>num[j]) {
					tmp=num[j];
					num[j]=num[j-1];
					num[j-1]=tmp;
					count++;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int a=0;a<num.length-1;a++ ) {
			sb.append(num[a]+" ");
		}
		System.out.println(sb.append(num[num.length-1]).toString());
		System.out.println(count);

	}
}

