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 [N];
		int i, j, t, k, l;
		int count = 0;
		
		for (i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		for(j = 0; j <= N-1; j++) {
			for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			}
			
		}
		
		for (l = 0;l < N - 1; l++) {
			System.out.print(A[l] + " ");
		}
		System.out.println(A[N-1]);
		System.out.println(count);
	}
} 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 [N];
		int i, j, t, k, l;
		int count = 0;
		
		for (i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		for(j = 0; j <= N-1; j++) {
			for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			}
			
		}
		
		for (l = 0;l < N - 1; l++) {
			System.out.print(A[l] + " ");
		}
		System.out.println(A[N-1]);
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int N = sc.nextInt();
		int []A = new int [N];
		int i, j, t, k, l;
		int count = 0;
		
		for (i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		for(j = 0; j <= N-1; j++) {
			for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			}
			
		}
		
		for (l = 0;l < N - 1; l++) {
			System.out.print(A[l] + " ");
		}
		System.out.println(A[N-1]);
		System.out.println(count);
	} main {
		Scanner sc  = new Scanner(System.in);
		int N = sc.nextInt();
		int []A = new int [N];
		int i, j, t, k, l;
		int count = 0;
		
		for (i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		for(j = 0; j <= N-1; j++) {
			for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			}
			
		}
		
		for (l = 0;l < N - 1; l++) {
			System.out.print(A[l] + " ");
		}
		System.out.println(A[N-1]);
		System.out.println(count);
	} 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 [N]; A new int [N] N int i i j j t t k k l; l int count = 0; count 0 for (i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		} i = 0; 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 for(j = 0; j <= N-1; j++) {
			for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			}
			
		} j = 0; j = 0 j 0 j <= N-1 j N-1 N 1 j++ j++ j {
			for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			}
			
		} {
			for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			}
			
		} for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			} k = N-1; k = N-1 k N-1 N 1 k > j k j k-- k-- k {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			} {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			} if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				} A[k] < A[k-1] A[k] A k A[k-1] A k-1 k 1 {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				} t = A[k] t A[k] A k A[k] = A[k-1] A[k] A k A[k-1] A k-1 k 1 A[k-1] = t A[k-1] A k-1 k 1 t count++ count for (l = 0;l < N - 1; l++) {
			System.out.print(A[l] + " ");
		} l = 0; l = 0 l 0 l < N - 1 l N - 1 N 1 l++ l++ l {
			System.out.print(A[l] + " ");
		} {
			System.out.print(A[l] + " ");
		} System.out.print(A[l] + " ") System.out.print System.out System System.out A[l] + " " A[l] A l " " 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(count) System.out.println System.out System System.out count 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 [N];
		int i, j, t, k, l;
		int count = 0;
		
		for (i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		for(j = 0; j <= N-1; j++) {
			for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			}
			
		}
		
		for (l = 0;l < N - 1; l++) {
			System.out.print(A[l] + " ");
		}
		System.out.println(A[N-1]);
		System.out.println(count);
	}
} public class Main {

	public static void main(String[] args) {
		Scanner sc  = new Scanner(System.in);
		int N = sc.nextInt();
		int []A = new int [N];
		int i, j, t, k, l;
		int count = 0;
		
		for (i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		for(j = 0; j <= N-1; j++) {
			for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			}
			
		}
		
		for (l = 0;l < N - 1; l++) {
			System.out.print(A[l] + " ");
		}
		System.out.println(A[N-1]);
		System.out.println(count);
	}
} 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 [N];
		int i, j, t, k, l;
		int count = 0;
		
		for (i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}

		for(j = 0; j <= N-1; j++) {
			for(k = N-1;k > j;k--) {
				if(A[k] < A[k-1]) {
					t = A[k];
					A[k] = A[k-1];
					A[k-1] = t;
					count++;
				}
			}
			
		}
		
		for (l = 0;l < N - 1; l++) {
			System.out.print(A[l] + " ");
		}
		System.out.println(A[N-1]);
		System.out.println(count);
	}
}
