
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),c=0;List<Integer> A=new ArrayList<>();
		for(int i=0;i<n;i++)A.add(cin.nextInt());
		
		boolean flag=true;
		while(flag) {
			flag=false;
			for(int i=n-1;i>0;i--) {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			}
		}
		
		
		for(int i=0;i<n;i++) {
			System.out.print(A.get(i));
			if(i!=n-1)System.out.print(" ");
		}
		System.out.println();
		System.out.println(c);
	}

}
 import java.util.*; util.* java public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),c=0;List<Integer> A=new ArrayList<>();
		for(int i=0;i<n;i++)A.add(cin.nextInt());
		
		boolean flag=true;
		while(flag) {
			flag=false;
			for(int i=n-1;i>0;i--) {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			}
		}
		
		
		for(int i=0;i<n;i++) {
			System.out.print(A.get(i));
			if(i!=n-1)System.out.print(" ");
		}
		System.out.println();
		System.out.println(c);
	}

} Main public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),c=0;List<Integer> A=new ArrayList<>();
		for(int i=0;i<n;i++)A.add(cin.nextInt());
		
		boolean flag=true;
		while(flag) {
			flag=false;
			for(int i=n-1;i>0;i--) {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			}
		}
		
		
		for(int i=0;i<n;i++) {
			System.out.print(A.get(i));
			if(i!=n-1)System.out.print(" ");
		}
		System.out.println();
		System.out.println(c);
	} main {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),c=0;List<Integer> A=new ArrayList<>();
		for(int i=0;i<n;i++)A.add(cin.nextInt());
		
		boolean flag=true;
		while(flag) {
			flag=false;
			for(int i=n-1;i>0;i--) {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			}
		}
		
		
		for(int i=0;i<n;i++) {
			System.out.print(A.get(i));
			if(i!=n-1)System.out.print(" ");
		}
		System.out.println();
		System.out.println(c);
	} Scanner cin=new Scanner(System.in); cin new Scanner(System.in) int n=cin.nextInt() n cin.nextInt() cin.nextInt cin c=0; c 0 List<Integer> A=new ArrayList<>(); A new ArrayList<>() for(int i=0;i<n;i++)A.add(cin.nextInt()); int i=0; int i=0; i 0 i<n i n i++ i++ i A.add(cin.nextInt()); A.add(cin.nextInt()) A.add A cin.nextInt() cin.nextInt cin boolean flag=true; flag true while(flag) {
			flag=false;
			for(int i=n-1;i>0;i--) {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			}
		} flag {
			flag=false;
			for(int i=n-1;i>0;i--) {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			}
		} flag=false flag false for(int i=n-1;i>0;i--) {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			} int i=n-1; int i=n-1; i n-1 n 1 i>0 i 0 i-- i-- i {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			} {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			} if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				} A.get(i)<A.get(i-1) A.get(i) A.get A i A.get(i-1) A.get A i-1 i 1 {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				} Collections.swap(A, i, i-1) Collections.swap Collections A i i-1 i 1 c++ c flag=true flag true for(int i=0;i<n;i++) {
			System.out.print(A.get(i));
			if(i!=n-1)System.out.print(" ");
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			System.out.print(A.get(i));
			if(i!=n-1)System.out.print(" ");
		} {
			System.out.print(A.get(i));
			if(i!=n-1)System.out.print(" ");
		} System.out.print(A.get(i)) System.out.print System.out System System.out A.get(i) A.get A i if(i!=n-1)System.out.print(" "); i!=n-1 i n-1 n 1 System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out System.out.println(c) System.out.println System.out System System.out c String[] args args public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),c=0;List<Integer> A=new ArrayList<>();
		for(int i=0;i<n;i++)A.add(cin.nextInt());
		
		boolean flag=true;
		while(flag) {
			flag=false;
			for(int i=n-1;i>0;i--) {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			}
		}
		
		
		for(int i=0;i<n;i++) {
			System.out.print(A.get(i));
			if(i!=n-1)System.out.print(" ");
		}
		System.out.println();
		System.out.println(c);
	}

} public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),c=0;List<Integer> A=new ArrayList<>();
		for(int i=0;i<n;i++)A.add(cin.nextInt());
		
		boolean flag=true;
		while(flag) {
			flag=false;
			for(int i=n-1;i>0;i--) {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			}
		}
		
		
		for(int i=0;i<n;i++) {
			System.out.print(A.get(i));
			if(i!=n-1)System.out.print(" ");
		}
		System.out.println();
		System.out.println(c);
	}

} Main

import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner cin=new Scanner(System.in);
		
		int n=cin.nextInt(),c=0;List<Integer> A=new ArrayList<>();
		for(int i=0;i<n;i++)A.add(cin.nextInt());
		
		boolean flag=true;
		while(flag) {
			flag=false;
			for(int i=n-1;i>0;i--) {
				if(A.get(i)<A.get(i-1)) {
					Collections.swap(A, i, i-1);
					c++;
					flag=true;
				}
				
			}
		}
		
		
		for(int i=0;i<n;i++) {
			System.out.print(A.get(i));
			if(i!=n-1)System.out.print(" ");
		}
		System.out.println();
		System.out.println(c);
	}

}

