import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] a = new int [100];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		
		int sw = 0;
		boolean flag = true;
		for(int i = 0; flag; i++) {
			flag = false;
			for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			}
		}
		
		for (int i1 = 0; i1 < N - 1; i1++) {
			System.out.print(a[i1] + " ");
		}
		System.out.println(a[N-1]);
		System.out.println(sw);
	}

}
 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[] a = new int [100];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		
		int sw = 0;
		boolean flag = true;
		for(int i = 0; flag; i++) {
			flag = false;
			for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			}
		}
		
		for (int i1 = 0; i1 < N - 1; i1++) {
			System.out.print(a[i1] + " ");
		}
		System.out.println(a[N-1]);
		System.out.println(sw);
	}

} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] a = new int [100];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		
		int sw = 0;
		boolean flag = true;
		for(int i = 0; flag; i++) {
			flag = false;
			for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			}
		}
		
		for (int i1 = 0; i1 < N - 1; i1++) {
			System.out.print(a[i1] + " ");
		}
		System.out.println(a[N-1]);
		System.out.println(sw);
	} main {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] a = new int [100];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		
		int sw = 0;
		boolean flag = true;
		for(int i = 0; flag; i++) {
			flag = false;
			for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			}
		}
		
		for (int i1 = 0; i1 < N - 1; i1++) {
			System.out.print(a[i1] + " ");
		}
		System.out.println(a[N-1]);
		System.out.println(sw);
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] a = new int [100]; a new int [100] 100 for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
			a[i] = sc.nextInt();
		} {
			a[i] = sc.nextInt();
		} a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc int sw = 0; sw 0 boolean flag = true; flag true for(int i = 0; flag; i++) {
			flag = false;
			for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			}
		} int i = 0; int i = 0; i 0 flag i++ i++ i {
			flag = false;
			for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			}
		} {
			flag = false;
			for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			}
		} flag = false flag false for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			} int j = N - 1; int j = N - 1; j N - 1 N 1 j >= i+1 j i+1 i 1 j-- j-- j {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			} {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			} if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				} a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				} int temp = a[j-1]; temp a[j-1] a j-1 j 1 a[j-1] = a[j] a[j-1] a j-1 j 1 a[j] a j a[j] = temp a[j] a j temp flag = true flag true sw++ sw for (int i1 = 0; i1 < N - 1; i1++) {
			System.out.print(a[i1] + " ");
		} int i1 = 0; int i1 = 0; i1 0 i1 < N - 1 i1 N - 1 N 1 i1++ i1++ i1 {
			System.out.print(a[i1] + " ");
		} {
			System.out.print(a[i1] + " ");
		} System.out.print(a[i1] + " ") System.out.print System.out System System.out a[i1] + " " a[i1] a i1 " " System.out.println(a[N-1]) System.out.println System.out System System.out a[N-1] a N-1 N 1 System.out.println(sw) System.out.println System.out System System.out sw String[] args args public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] a = new int [100];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		
		int sw = 0;
		boolean flag = true;
		for(int i = 0; flag; i++) {
			flag = false;
			for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			}
		}
		
		for (int i1 = 0; i1 < N - 1; i1++) {
			System.out.print(a[i1] + " ");
		}
		System.out.println(a[N-1]);
		System.out.println(sw);
	}

} public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		
		int[] a = new int [100];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		
		int sw = 0;
		boolean flag = true;
		for(int i = 0; flag; i++) {
			flag = false;
			for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			}
		}
		
		for (int i1 = 0; i1 < N - 1; i1++) {
			System.out.print(a[i1] + " ");
		}
		System.out.println(a[N-1]);
		System.out.println(sw);
	}

} 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[] a = new int [100];
		for(int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
		}
		
		int sw = 0;
		boolean flag = true;
		for(int i = 0; flag; i++) {
			flag = false;
			for (int j = N - 1; j >= i+1; j--) {
				if(a[j] < a[j-1]) {
					int temp = a[j-1];
					a[j-1] = a[j];
					a[j] = temp;
					flag = true;
					sw++;
				}
			}
		}
		
		for (int i1 = 0; i1 < N - 1; i1++) {
			System.out.print(a[i1] + " ");
		}
		System.out.println(a[N-1]);
		System.out.println(sw);
	}

}

