import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[n];
		for(int i=0; i < n; i++){
			num[i] = sc.nextInt();
		}
		
		int temp;
		int count = 0;
		for(int i=0; i <  num.length; i++){
			for(int j=num.length-1; j > i; j--){
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			}
		}
		System.out.print(num[0]);
		for(int i=1; i < num.length; i++){
			System.out.print(" " + num[i]);
		}
		System.out.println();
		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[] num = new int[n];
		for(int i=0; i < n; i++){
			num[i] = sc.nextInt();
		}
		
		int temp;
		int count = 0;
		for(int i=0; i <  num.length; i++){
			for(int j=num.length-1; j > i; j--){
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			}
		}
		System.out.print(num[0]);
		for(int i=1; i < num.length; i++){
			System.out.print(" " + num[i]);
		}
		System.out.println();
		System.out.println(count);
	}
} Main public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[n];
		for(int i=0; i < n; i++){
			num[i] = sc.nextInt();
		}
		
		int temp;
		int count = 0;
		for(int i=0; i <  num.length; i++){
			for(int j=num.length-1; j > i; j--){
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			}
		}
		System.out.print(num[0]);
		for(int i=1; i < num.length; i++){
			System.out.print(" " + num[i]);
		}
		System.out.println();
		System.out.println(count);
	} main {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[n];
		for(int i=0; i < n; i++){
			num[i] = sc.nextInt();
		}
		
		int temp;
		int count = 0;
		for(int i=0; i <  num.length; i++){
			for(int j=num.length-1; j > i; j--){
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			}
		}
		System.out.print(num[0]);
		for(int i=1; i < num.length; i++){
			System.out.print(" " + num[i]);
		}
		System.out.println();
		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[] num = new int[n]; num new int[n] n for(int i=0; i < n; i++){
			num[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i < n i n i++ i++ i {
			num[i] = sc.nextInt();
		} {
			num[i] = sc.nextInt();
		} num[i] = sc.nextInt() num[i] num i sc.nextInt() sc.nextInt sc int temp; temp int count = 0; count 0 for(int i=0; i <  num.length; i++){
			for(int j=num.length-1; j > i; j--){
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			}
		} int i=0; int i=0; i 0 i <  num.length i num.length num num.length i++ i++ i {
			for(int j=num.length-1; j > i; j--){
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			}
		} {
			for(int j=num.length-1; j > i; j--){
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			}
		} for(int j=num.length-1; j > i; j--){
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					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] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			} {
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			} if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				} num[j] < num[j-1] num[j] num j num[j-1] num j-1 j 1 {
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				} temp = num[j] temp num[j] num j num[j] = num[j-1] num[j] num j num[j-1] num j-1 j 1 num[j-1] = temp num[j-1] num j-1 j 1 temp count++ count System.out.print(num[0]) System.out.print System.out System System.out num[0] num 0 for(int i=1; i < num.length; i++){
			System.out.print(" " + num[i]);
		} int i=1; int i=1; i 1 i < num.length i num.length num num.length i++ i++ i {
			System.out.print(" " + num[i]);
		} {
			System.out.print(" " + num[i]);
		} System.out.print(" " + num[i]) System.out.print System.out System System.out " " + num[i] " " num[i] num i System.out.println() System.out.println System.out System System.out 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[] num = new int[n];
		for(int i=0; i < n; i++){
			num[i] = sc.nextInt();
		}
		
		int temp;
		int count = 0;
		for(int i=0; i <  num.length; i++){
			for(int j=num.length-1; j > i; j--){
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			}
		}
		System.out.print(num[0]);
		for(int i=1; i < num.length; i++){
			System.out.print(" " + num[i]);
		}
		System.out.println();
		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] num = new int[n];
		for(int i=0; i < n; i++){
			num[i] = sc.nextInt();
		}
		
		int temp;
		int count = 0;
		for(int i=0; i <  num.length; i++){
			for(int j=num.length-1; j > i; j--){
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			}
		}
		System.out.print(num[0]);
		for(int i=1; i < num.length; i++){
			System.out.print(" " + num[i]);
		}
		System.out.println();
		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[] num = new int[n];
		for(int i=0; i < n; i++){
			num[i] = sc.nextInt();
		}
		
		int temp;
		int count = 0;
		for(int i=0; i <  num.length; i++){
			for(int j=num.length-1; j > i; j--){
				if(num[j] < num[j-1]){
					temp = num[j];
					num[j] = num[j-1];
					num[j-1] = temp;
					count++;
				}
			}
		}
		System.out.print(num[0]);
		for(int i=1; i < num.length; i++){
			System.out.print(" " + num[i]);
		}
		System.out.println();
		System.out.println(count);
	}
}