import java.util.*;
import java.io.*;
public class Main {
	static int n = 0;
	
	public static void bubble_sort(int[] a) {
		int swapCount = 0;
		for (int i = 0; i < n; i++) {
			
			// search for unsorted pairs from the back
			for (int j = n-1; j > i; j--) {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			}
			
			// print sorted elements
			if (i < n-1) System.out.print(a[i] + " "); 
			else
				System.out.println(a[i]);
		}
		
		// print swapCount on a new line
		System.out.println(swapCount);
	}
	
	public static void main (String args[]) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) 
			a[i] = sc.nextInt();
		bubble_sort(a);
	}
} import java.util.*; util.* java import java.io.*; io.* java public class Main {
	static int n = 0;
	
	public static void bubble_sort(int[] a) {
		int swapCount = 0;
		for (int i = 0; i < n; i++) {
			
			// search for unsorted pairs from the back
			for (int j = n-1; j > i; j--) {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			}
			
			// print sorted elements
			if (i < n-1) System.out.print(a[i] + " "); 
			else
				System.out.println(a[i]);
		}
		
		// print swapCount on a new line
		System.out.println(swapCount);
	}
	
	public static void main (String args[]) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) 
			a[i] = sc.nextInt();
		bubble_sort(a);
	}
} Main static int n = 0; n 0 public static void bubble_sort(int[] a) {
		int swapCount = 0;
		for (int i = 0; i < n; i++) {
			
			// search for unsorted pairs from the back
			for (int j = n-1; j > i; j--) {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			}
			
			// print sorted elements
			if (i < n-1) System.out.print(a[i] + " "); 
			else
				System.out.println(a[i]);
		}
		
		// print swapCount on a new line
		System.out.println(swapCount);
	} bubble_sort {
		int swapCount = 0;
		for (int i = 0; i < n; i++) {
			
			// search for unsorted pairs from the back
			for (int j = n-1; j > i; j--) {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			}
			
			// print sorted elements
			if (i < n-1) System.out.print(a[i] + " "); 
			else
				System.out.println(a[i]);
		}
		
		// print swapCount on a new line
		System.out.println(swapCount);
	} int swapCount = 0; swapCount 0 for (int i = 0; i < n; i++) {
			
			// search for unsorted pairs from the back
			for (int j = n-1; j > i; j--) {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			}
			
			// print sorted elements
			if (i < n-1) System.out.print(a[i] + " "); 
			else
				System.out.println(a[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			
			// search for unsorted pairs from the back
			for (int j = n-1; j > i; j--) {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			}
			
			// print sorted elements
			if (i < n-1) System.out.print(a[i] + " "); 
			else
				System.out.println(a[i]);
		} {
			
			// search for unsorted pairs from the back
			for (int j = n-1; j > i; j--) {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			}
			
			// print sorted elements
			if (i < n-1) System.out.print(a[i] + " "); 
			else
				System.out.println(a[i]);
		} for (int j = n-1; j > i; j--) {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			} 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]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			} {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			} if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				} a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				} int tmp = a[j]; tmp a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1] = tmp a[j-1] a j-1 j 1 tmp swapCount++ swapCount if (i < n-1) System.out.print(a[i] + " "); 
			else
				System.out.println(a[i]); i < n-1 i n-1 n 1 System.out.print(a[i] + " ") System.out.print System.out System System.out a[i] + " " a[i] a i " " System.out.println(a[i]) System.out.println System.out System System.out a[i] a i System.out.println(swapCount) System.out.println System.out System System.out swapCount int[] a a public static void main (String args[]) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) 
			a[i] = sc.nextInt();
		bubble_sort(a);
	} main {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) 
			a[i] = sc.nextInt();
		bubble_sort(a);
	} @SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc int[] a = new int[n]; a new int[n] n 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] a i sc.nextInt() sc.nextInt sc bubble_sort(a) bubble_sort a String args[] args public class Main {
	static int n = 0;
	
	public static void bubble_sort(int[] a) {
		int swapCount = 0;
		for (int i = 0; i < n; i++) {
			
			// search for unsorted pairs from the back
			for (int j = n-1; j > i; j--) {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			}
			
			// print sorted elements
			if (i < n-1) System.out.print(a[i] + " "); 
			else
				System.out.println(a[i]);
		}
		
		// print swapCount on a new line
		System.out.println(swapCount);
	}
	
	public static void main (String args[]) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) 
			a[i] = sc.nextInt();
		bubble_sort(a);
	}
} public class Main {
	static int n = 0;
	
	public static void bubble_sort(int[] a) {
		int swapCount = 0;
		for (int i = 0; i < n; i++) {
			
			// search for unsorted pairs from the back
			for (int j = n-1; j > i; j--) {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			}
			
			// print sorted elements
			if (i < n-1) System.out.print(a[i] + " "); 
			else
				System.out.println(a[i]);
		}
		
		// print swapCount on a new line
		System.out.println(swapCount);
	}
	
	public static void main (String args[]) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) 
			a[i] = sc.nextInt();
		bubble_sort(a);
	}
} Main
import java.util.*;
import java.io.*;
public class Main {
	static int n = 0;
	
	public static void bubble_sort(int[] a) {
		int swapCount = 0;
		for (int i = 0; i < n; i++) {
			
			// search for unsorted pairs from the back
			for (int j = n-1; j > i; j--) {
				if (a[j] < a[j-1]) {
					
					// swap a[j], a[j-1]
					int tmp = a[j];
					a[j] = a[j-1];
					a[j-1] = tmp;
					
					// increase swapCount
					swapCount++;
				}
			}
			
			// print sorted elements
			if (i < n-1) System.out.print(a[i] + " "); 
			else
				System.out.println(a[i]);
		}
		
		// print swapCount on a new line
		System.out.println(swapCount);
	}
	
	public static void main (String args[]) {
		@SuppressWarnings("resource")
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) 
			a[i] = sc.nextInt();
		bubble_sort(a);
	}
}