import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc  =new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<n;i++){
			nums[i] = sc.nextInt();
		}
		BubbleSort(nums);
		
		
	}
	public static void  BubbleSort(int[] nums){
		int swap_count =0;
		for(int i=0;i<nums.length;i++){
			for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			}
		}
		for(int i=0;i<nums.length;i++){
			if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]);
		}
		System.out.println();
		System.out.println(swap_count);
	}
	public static void swap(int[] nums,int i,int j){
		int temp = nums[i];
		nums[i] = nums[j];
		nums[j] = temp; 
	}
} import java.util.*; util.* java public class Main {
	public static void main(String args[]){
		Scanner sc  =new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<n;i++){
			nums[i] = sc.nextInt();
		}
		BubbleSort(nums);
		
		
	}
	public static void  BubbleSort(int[] nums){
		int swap_count =0;
		for(int i=0;i<nums.length;i++){
			for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			}
		}
		for(int i=0;i<nums.length;i++){
			if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]);
		}
		System.out.println();
		System.out.println(swap_count);
	}
	public static void swap(int[] nums,int i,int j){
		int temp = nums[i];
		nums[i] = nums[j];
		nums[j] = temp; 
	}
} Main public static void main(String args[]){
		Scanner sc  =new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<n;i++){
			nums[i] = sc.nextInt();
		}
		BubbleSort(nums);
		
		
	} main {
		Scanner sc  =new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<n;i++){
			nums[i] = sc.nextInt();
		}
		BubbleSort(nums);
		
		
	} Scanner sc  =new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] nums = new int[n]; nums new int[n] n for(int i=0;i<n;i++){
			nums[i] = sc.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			nums[i] = sc.nextInt();
		} {
			nums[i] = sc.nextInt();
		} nums[i] = sc.nextInt() nums[i] nums i sc.nextInt() sc.nextInt sc BubbleSort(nums) BubbleSort nums String args[] args public static void  BubbleSort(int[] nums){
		int swap_count =0;
		for(int i=0;i<nums.length;i++){
			for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			}
		}
		for(int i=0;i<nums.length;i++){
			if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]);
		}
		System.out.println();
		System.out.println(swap_count);
	} BubbleSort {
		int swap_count =0;
		for(int i=0;i<nums.length;i++){
			for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			}
		}
		for(int i=0;i<nums.length;i++){
			if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]);
		}
		System.out.println();
		System.out.println(swap_count);
	} int swap_count =0; swap_count 0 for(int i=0;i<nums.length;i++){
			for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			}
		} int i=0; int i=0; i 0 i<nums.length i nums.length nums nums.length i++ i++ i {
			for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			}
		} {
			for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			}
		} for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			} int j=1; int j=1; j 1 j<nums.length-i j nums.length-i nums.length nums nums.length i j++ j++ j {
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			} {
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			} if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				} nums[j]<nums[j-1] nums[j] nums j nums[j-1] nums j-1 j 1 {
					swap(nums,j,j-1);
					swap_count++;
				} swap(nums,j,j-1) swap nums j j-1 j 1 swap_count++ swap_count for(int i=0;i<nums.length;i++){
			if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]);
		} int i=0; int i=0; i 0 i<nums.length i nums.length nums nums.length i++ i++ i {
			if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]);
		} {
			if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]);
		} if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]); i==0 i 0 System.out.print(nums[i]) System.out.print System.out System System.out nums[i] nums i System.out.print(" "+nums[i]) System.out.print System.out System System.out " "+nums[i] " " nums[i] nums i System.out.println() System.out.println System.out System System.out System.out.println(swap_count) System.out.println System.out System System.out swap_count int[] nums nums public static void swap(int[] nums,int i,int j){
		int temp = nums[i];
		nums[i] = nums[j];
		nums[j] = temp; 
	} swap {
		int temp = nums[i];
		nums[i] = nums[j];
		nums[j] = temp; 
	} int temp = nums[i]; temp nums[i] nums i nums[i] = nums[j] nums[i] nums i nums[j] nums j nums[j] = temp nums[j] nums j temp int[] nums nums int i i int j j public class Main {
	public static void main(String args[]){
		Scanner sc  =new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<n;i++){
			nums[i] = sc.nextInt();
		}
		BubbleSort(nums);
		
		
	}
	public static void  BubbleSort(int[] nums){
		int swap_count =0;
		for(int i=0;i<nums.length;i++){
			for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			}
		}
		for(int i=0;i<nums.length;i++){
			if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]);
		}
		System.out.println();
		System.out.println(swap_count);
	}
	public static void swap(int[] nums,int i,int j){
		int temp = nums[i];
		nums[i] = nums[j];
		nums[j] = temp; 
	}
} public class Main {
	public static void main(String args[]){
		Scanner sc  =new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<n;i++){
			nums[i] = sc.nextInt();
		}
		BubbleSort(nums);
		
		
	}
	public static void  BubbleSort(int[] nums){
		int swap_count =0;
		for(int i=0;i<nums.length;i++){
			for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			}
		}
		for(int i=0;i<nums.length;i++){
			if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]);
		}
		System.out.println();
		System.out.println(swap_count);
	}
	public static void swap(int[] nums,int i,int j){
		int temp = nums[i];
		nums[i] = nums[j];
		nums[j] = temp; 
	}
} Main
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner sc  =new Scanner(System.in);
		int n = sc.nextInt();
		int[] nums = new int[n];
		for(int i=0;i<n;i++){
			nums[i] = sc.nextInt();
		}
		BubbleSort(nums);
		
		
	}
	public static void  BubbleSort(int[] nums){
		int swap_count =0;
		for(int i=0;i<nums.length;i++){
			for(int j=1;j<nums.length-i;j++){
				if(nums[j]<nums[j-1]){
					swap(nums,j,j-1);
					swap_count++;
				}
			}
		}
		for(int i=0;i<nums.length;i++){
			if(i==0)System.out.print(nums[i]);
			else System.out.print(" "+nums[i]);
		}
		System.out.println();
		System.out.println(swap_count);
	}
	public static void swap(int[] nums,int i,int j){
		int temp = nums[i];
		nums[i] = nums[j];
		nums[j] = temp; 
	}
}