import java.util.*;
public class Main{
	static int count = 0 ;
	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);
		for(int i=0;i<nums.length;i++){
			if(i>0) System.out.print(" ");
			System.out.print(nums[i]);
		}
		System.out.println();
		System.out.println(count);
	}
	public static void bubbleSort(int[] A){
		int N = A.length;
		for(int i=0;i<N;i++){
			for(int j=1;j<N-i;j++){
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			}
		}
	}
} import java.util.*; util.* java public class Main{
	static int count = 0 ;
	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);
		for(int i=0;i<nums.length;i++){
			if(i>0) System.out.print(" ");
			System.out.print(nums[i]);
		}
		System.out.println();
		System.out.println(count);
	}
	public static void bubbleSort(int[] A){
		int N = A.length;
		for(int i=0;i<N;i++){
			for(int j=1;j<N-i;j++){
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			}
		}
	}
} Main static int count = 0 ; count 0 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);
		for(int i=0;i<nums.length;i++){
			if(i>0) System.out.print(" ");
			System.out.print(nums[i]);
		}
		System.out.println();
		System.out.println(count);
	} 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);
		for(int i=0;i<nums.length;i++){
			if(i>0) System.out.print(" ");
			System.out.print(nums[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[] 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 for(int i=0;i<nums.length;i++){
			if(i>0) System.out.print(" ");
			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(" ");
			System.out.print(nums[i]);
		} {
			if(i>0) System.out.print(" ");
			System.out.print(nums[i]);
		} if(i>0) System.out.print(" "); i>0 i 0 System.out.print(" ") System.out.print System.out System System.out " " System.out.print(nums[i]) System.out.print System.out System System.out nums[i] nums 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 static void bubbleSort(int[] A){
		int N = A.length;
		for(int i=0;i<N;i++){
			for(int j=1;j<N-i;j++){
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			}
		}
	} bubbleSort {
		int N = A.length;
		for(int i=0;i<N;i++){
			for(int j=1;j<N-i;j++){
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			}
		}
	} int N = A.length; N A.length A A.length for(int i=0;i<N;i++){
			for(int j=1;j<N-i;j++){
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			for(int j=1;j<N-i;j++){
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			}
		} {
			for(int j=1;j<N-i;j++){
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			}
		} for(int j=1;j<N-i;j++){
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			} int j=1; int j=1; j 1 j<N-i j N-i N i j++ j++ j {
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			} {
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			} if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				} A[j]<A[j-1] A[j] A j A[j-1] A j-1 j 1 {
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				} count++ count int t = A[j]; t A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = t A[j-1] A j-1 j 1 t int[] A A public class Main{
	static int count = 0 ;
	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);
		for(int i=0;i<nums.length;i++){
			if(i>0) System.out.print(" ");
			System.out.print(nums[i]);
		}
		System.out.println();
		System.out.println(count);
	}
	public static void bubbleSort(int[] A){
		int N = A.length;
		for(int i=0;i<N;i++){
			for(int j=1;j<N-i;j++){
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			}
		}
	}
} public class Main{
	static int count = 0 ;
	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);
		for(int i=0;i<nums.length;i++){
			if(i>0) System.out.print(" ");
			System.out.print(nums[i]);
		}
		System.out.println();
		System.out.println(count);
	}
	public static void bubbleSort(int[] A){
		int N = A.length;
		for(int i=0;i<N;i++){
			for(int j=1;j<N-i;j++){
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			}
		}
	}
} Main
import java.util.*;
public class Main{
	static int count = 0 ;
	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);
		for(int i=0;i<nums.length;i++){
			if(i>0) System.out.print(" ");
			System.out.print(nums[i]);
		}
		System.out.println();
		System.out.println(count);
	}
	public static void bubbleSort(int[] A){
		int N = A.length;
		for(int i=0;i<N;i++){
			for(int j=1;j<N-i;j++){
				if(A[j]<A[j-1]){
					count++;
					int t = A[j];
					A[j] = A[j-1];
					A[j-1] = t; 
				}
			}
		}
	}
}