import java.util.Scanner;
public class Main {

	public static void main(String [] args) {
		
		Scanner in = new Scanner(System.in);
		int numSwaps = 0;
		
		int n = in.nextInt();
		int [] arr = new int [n];
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		for(int j = 0; j < n - 1; j++) {
			
			
			for(int h = n - 1; h > j ; h--) {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			}
		}
		
		for(int k = 0; k < n; k++) {
			System.out.print(arr[k]);
			
			if(k != n - 1) {
				System.out.print(" ");
			}
		}
		
		System.out.println("\n" + numSwaps);
	}
}
 import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String [] args) {
		
		Scanner in = new Scanner(System.in);
		int numSwaps = 0;
		
		int n = in.nextInt();
		int [] arr = new int [n];
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		for(int j = 0; j < n - 1; j++) {
			
			
			for(int h = n - 1; h > j ; h--) {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			}
		}
		
		for(int k = 0; k < n; k++) {
			System.out.print(arr[k]);
			
			if(k != n - 1) {
				System.out.print(" ");
			}
		}
		
		System.out.println("\n" + numSwaps);
	}
} Main public static void main(String [] args) {
		
		Scanner in = new Scanner(System.in);
		int numSwaps = 0;
		
		int n = in.nextInt();
		int [] arr = new int [n];
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		for(int j = 0; j < n - 1; j++) {
			
			
			for(int h = n - 1; h > j ; h--) {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			}
		}
		
		for(int k = 0; k < n; k++) {
			System.out.print(arr[k]);
			
			if(k != n - 1) {
				System.out.print(" ");
			}
		}
		
		System.out.println("\n" + numSwaps);
	} main {
		
		Scanner in = new Scanner(System.in);
		int numSwaps = 0;
		
		int n = in.nextInt();
		int [] arr = new int [n];
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		for(int j = 0; j < n - 1; j++) {
			
			
			for(int h = n - 1; h > j ; h--) {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			}
		}
		
		for(int k = 0; k < n; k++) {
			System.out.print(arr[k]);
			
			if(k != n - 1) {
				System.out.print(" ");
			}
		}
		
		System.out.println("\n" + numSwaps);
	} Scanner in = new Scanner(System.in); in new Scanner(System.in) int numSwaps = 0; numSwaps 0 int n = in.nextInt(); n in.nextInt() in.nextInt in int [] arr = new int [n]; arr new int [n] n for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			arr[i] = in.nextInt();
		} {
			arr[i] = in.nextInt();
		} arr[i] = in.nextInt() arr[i] arr i in.nextInt() in.nextInt in for(int j = 0; j < n - 1; j++) {
			
			
			for(int h = n - 1; h > j ; h--) {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			}
		} int j = 0; int j = 0; j 0 j < n - 1 j n - 1 n 1 j++ j++ j {
			
			
			for(int h = n - 1; h > j ; h--) {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			}
		} {
			
			
			for(int h = n - 1; h > j ; h--) {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			}
		} for(int h = n - 1; h > j ; h--) {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			} int h = n - 1; int h = n - 1; h n - 1 n 1 h > j h j h-- h-- h {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			} {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			} if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				} arr[h] < arr[h - 1] arr[h] arr h arr[h - 1] arr h - 1 h 1 {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				} int temp = arr[h]; temp arr[h] arr h arr[h] = arr[h - 1] arr[h] arr h arr[h - 1] arr h - 1 h 1 arr[h - 1] = temp arr[h - 1] arr h - 1 h 1 temp numSwaps++ numSwaps for(int k = 0; k < n; k++) {
			System.out.print(arr[k]);
			
			if(k != n - 1) {
				System.out.print(" ");
			}
		} int k = 0; int k = 0; k 0 k < n k n k++ k++ k {
			System.out.print(arr[k]);
			
			if(k != n - 1) {
				System.out.print(" ");
			}
		} {
			System.out.print(arr[k]);
			
			if(k != n - 1) {
				System.out.print(" ");
			}
		} System.out.print(arr[k]) System.out.print System.out System System.out arr[k] arr k if(k != n - 1) {
				System.out.print(" ");
			} k != n - 1 k n - 1 n 1 {
				System.out.print(" ");
			} System.out.print(" ") System.out.print System.out System System.out " " System.out.println("\n" + numSwaps) System.out.println System.out System System.out "\n" + numSwaps "\n" numSwaps String [] args args public class Main {

	public static void main(String [] args) {
		
		Scanner in = new Scanner(System.in);
		int numSwaps = 0;
		
		int n = in.nextInt();
		int [] arr = new int [n];
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		for(int j = 0; j < n - 1; j++) {
			
			
			for(int h = n - 1; h > j ; h--) {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			}
		}
		
		for(int k = 0; k < n; k++) {
			System.out.print(arr[k]);
			
			if(k != n - 1) {
				System.out.print(" ");
			}
		}
		
		System.out.println("\n" + numSwaps);
	}
} public class Main {

	public static void main(String [] args) {
		
		Scanner in = new Scanner(System.in);
		int numSwaps = 0;
		
		int n = in.nextInt();
		int [] arr = new int [n];
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		for(int j = 0; j < n - 1; j++) {
			
			
			for(int h = n - 1; h > j ; h--) {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			}
		}
		
		for(int k = 0; k < n; k++) {
			System.out.print(arr[k]);
			
			if(k != n - 1) {
				System.out.print(" ");
			}
		}
		
		System.out.println("\n" + numSwaps);
	}
} Main
import java.util.Scanner;
public class Main {

	public static void main(String [] args) {
		
		Scanner in = new Scanner(System.in);
		int numSwaps = 0;
		
		int n = in.nextInt();
		int [] arr = new int [n];
		
		for(int i = 0; i < n; i++) {
			arr[i] = in.nextInt();
		}
		
		for(int j = 0; j < n - 1; j++) {
			
			
			for(int h = n - 1; h > j ; h--) {
				
				if(arr[h] < arr[h - 1]) {
					int temp = arr[h];
					arr[h] = arr[h - 1];
					arr[h - 1] = temp;
					numSwaps++;
				}
			}
		}
		
		for(int k = 0; k < n; k++) {
			System.out.print(arr[k]);
			
			if(k != n - 1) {
				System.out.print(" ");
			}
		}
		
		System.out.println("\n" + numSwaps);
	}
}

