import java.util.*;

public class Main {
	static int swap=0;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A =new int[N];
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		BubbleSort(A);
		for(int i=0;i<N;i++){
			if(i==N-1){
				System.out.println(A[i]);
			}else{
				System.out.print(A[i]+" ");
			}
		}
		System.out.println(swap);
	}
	
	static void BubbleSort(int[] a){
		for(int i=0;i<a.length;i++){
			for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			}
		}
	}
} import java.util.*; util.* java public class Main {
	static int swap=0;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A =new int[N];
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		BubbleSort(A);
		for(int i=0;i<N;i++){
			if(i==N-1){
				System.out.println(A[i]);
			}else{
				System.out.print(A[i]+" ");
			}
		}
		System.out.println(swap);
	}
	
	static void BubbleSort(int[] a){
		for(int i=0;i<a.length;i++){
			for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			}
		}
	}
} Main static int swap=0; swap 0 public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A =new int[N];
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		BubbleSort(A);
		for(int i=0;i<N;i++){
			if(i==N-1){
				System.out.println(A[i]);
			}else{
				System.out.print(A[i]+" ");
			}
		}
		System.out.println(swap);
	} main {
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A =new int[N];
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		BubbleSort(A);
		for(int i=0;i<N;i++){
			if(i==N-1){
				System.out.println(A[i]);
			}else{
				System.out.print(A[i]+" ");
			}
		}
		System.out.println(swap);
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int 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]=sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc BubbleSort(A) BubbleSort A for(int i=0;i<N;i++){
			if(i==N-1){
				System.out.println(A[i]);
			}else{
				System.out.print(A[i]+" ");
			}
		} int i=0; int i=0; i 0 i<N i N i++ i++ i {
			if(i==N-1){
				System.out.println(A[i]);
			}else{
				System.out.print(A[i]+" ");
			}
		} {
			if(i==N-1){
				System.out.println(A[i]);
			}else{
				System.out.print(A[i]+" ");
			}
		} if(i==N-1){
				System.out.println(A[i]);
			}else{
				System.out.print(A[i]+" ");
			} i==N-1 i N-1 N 1 {
				System.out.println(A[i]);
			} System.out.println(A[i]) System.out.println System.out System System.out A[i] A i {
				System.out.print(A[i]+" ");
			} System.out.print(A[i]+" ") System.out.print System.out System System.out A[i]+" " A[i] A i " " System.out.println(swap) System.out.println System.out System System.out swap String[] args args static void BubbleSort(int[] a){
		for(int i=0;i<a.length;i++){
			for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			}
		}
	} BubbleSort {
		for(int i=0;i<a.length;i++){
			for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			}
		}
	} for(int i=0;i<a.length;i++){
			for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			}
		} int i=0; int i=0; i 0 i<a.length i a.length a a.length i++ i++ i {
			for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			}
		} {
			for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			}
		} for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			} int j=a.length-1; int j=a.length-1; j a.length-1 a.length a a.length 1 j>i j i j-- j-- j {
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			} {
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			} if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				} a[j]<a[j-1] a[j] a j a[j-1] a j-1 j 1 {
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				} 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 swap++ swap int[] a a public class Main {
	static int swap=0;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A =new int[N];
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		BubbleSort(A);
		for(int i=0;i<N;i++){
			if(i==N-1){
				System.out.println(A[i]);
			}else{
				System.out.print(A[i]+" ");
			}
		}
		System.out.println(swap);
	}
	
	static void BubbleSort(int[] a){
		for(int i=0;i<a.length;i++){
			for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			}
		}
	}
} public class Main {
	static int swap=0;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A =new int[N];
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		BubbleSort(A);
		for(int i=0;i<N;i++){
			if(i==N-1){
				System.out.println(A[i]);
			}else{
				System.out.print(A[i]+" ");
			}
		}
		System.out.println(swap);
	}
	
	static void BubbleSort(int[] a){
		for(int i=0;i<a.length;i++){
			for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			}
		}
	}
} Main
import java.util.*;

public class Main {
	static int swap=0;
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A =new int[N];
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		BubbleSort(A);
		for(int i=0;i<N;i++){
			if(i==N-1){
				System.out.println(A[i]);
			}else{
				System.out.print(A[i]+" ");
			}
		}
		System.out.println(swap);
	}
	
	static void BubbleSort(int[] a){
		for(int i=0;i<a.length;i++){
			for(int j=a.length-1;j>i;j--){
				if(a[j]<a[j-1]){
					int t=a[j];
					a[j]=a[j-1];
					a[j-1]=t;
					swap++;
				}
			}
		}
	}
}