import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int[] arr= new int[n];
		for(int i=0;i<n;i++){
			arr[i]=Integer.valueOf(sc.next());
		}
		sc.close();
		
		int count=0;
		boolean f=true;
		while(f){
			f=false;
			for(int i=n-1;i>0;i--){
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			}
			
		}
		System.out.print(arr[0]);
		for(int i=1;i<n;i++){
			System.out.print(" "+arr[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=Integer.valueOf(sc.next());
		int[] arr= new int[n];
		for(int i=0;i<n;i++){
			arr[i]=Integer.valueOf(sc.next());
		}
		sc.close();
		
		int count=0;
		boolean f=true;
		while(f){
			f=false;
			for(int i=n-1;i>0;i--){
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			}
			
		}
		System.out.print(arr[0]);
		for(int i=1;i<n;i++){
			System.out.print(" "+arr[i]);
		}
		System.out.println();
		System.out.println(count);
	}

} Main public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int[] arr= new int[n];
		for(int i=0;i<n;i++){
			arr[i]=Integer.valueOf(sc.next());
		}
		sc.close();
		
		int count=0;
		boolean f=true;
		while(f){
			f=false;
			for(int i=n-1;i>0;i--){
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			}
			
		}
		System.out.print(arr[0]);
		for(int i=1;i<n;i++){
			System.out.print(" "+arr[i]);
		}
		System.out.println();
		System.out.println(count);
	} main {
		Scanner sc=new Scanner(System.in);
		int n=Integer.valueOf(sc.next());
		int[] arr= new int[n];
		for(int i=0;i<n;i++){
			arr[i]=Integer.valueOf(sc.next());
		}
		sc.close();
		
		int count=0;
		boolean f=true;
		while(f){
			f=false;
			for(int i=n-1;i>0;i--){
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			}
			
		}
		System.out.print(arr[0]);
		for(int i=1;i<n;i++){
			System.out.print(" "+arr[i]);
		}
		System.out.println();
		System.out.println(count);
	} Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int n=Integer.valueOf(sc.next()); n Integer.valueOf(sc.next()) Integer.valueOf Integer sc.next() sc.next sc int[] arr= new int[n]; arr new int[n] n for(int i=0;i<n;i++){
			arr[i]=Integer.valueOf(sc.next());
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			arr[i]=Integer.valueOf(sc.next());
		} {
			arr[i]=Integer.valueOf(sc.next());
		} arr[i]=Integer.valueOf(sc.next()) arr[i] arr i Integer.valueOf(sc.next()) Integer.valueOf Integer sc.next() sc.next sc sc.close() sc.close sc int count=0; count 0 boolean f=true; f true while(f){
			f=false;
			for(int i=n-1;i>0;i--){
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			}
			
		} f {
			f=false;
			for(int i=n-1;i>0;i--){
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			}
			
		} f=false f false for(int i=n-1;i>0;i--){
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			} int i=n-1; int i=n-1; i n-1 n 1 i>0 i 0 i-- i-- i {
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			} {
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			} int a=arr[i]; a arr[i] arr i int b=arr[i-1]; b arr[i-1] arr i-1 i 1 if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				} a<b a b {
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				} arr[i]=b arr[i] arr i b arr[i-1]=a arr[i-1] arr i-1 i 1 a count++ count f=true f true System.out.print(arr[0]) System.out.print System.out System System.out arr[0] arr 0 for(int i=1;i<n;i++){
			System.out.print(" "+arr[i]);
		} int i=1; int i=1; i 1 i<n i n i++ i++ i {
			System.out.print(" "+arr[i]);
		} {
			System.out.print(" "+arr[i]);
		} System.out.print(" "+arr[i]) System.out.print System.out System System.out " "+arr[i] " " arr[i] arr 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=Integer.valueOf(sc.next());
		int[] arr= new int[n];
		for(int i=0;i<n;i++){
			arr[i]=Integer.valueOf(sc.next());
		}
		sc.close();
		
		int count=0;
		boolean f=true;
		while(f){
			f=false;
			for(int i=n-1;i>0;i--){
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			}
			
		}
		System.out.print(arr[0]);
		for(int i=1;i<n;i++){
			System.out.print(" "+arr[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=Integer.valueOf(sc.next());
		int[] arr= new int[n];
		for(int i=0;i<n;i++){
			arr[i]=Integer.valueOf(sc.next());
		}
		sc.close();
		
		int count=0;
		boolean f=true;
		while(f){
			f=false;
			for(int i=n-1;i>0;i--){
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			}
			
		}
		System.out.print(arr[0]);
		for(int i=1;i<n;i++){
			System.out.print(" "+arr[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=Integer.valueOf(sc.next());
		int[] arr= new int[n];
		for(int i=0;i<n;i++){
			arr[i]=Integer.valueOf(sc.next());
		}
		sc.close();
		
		int count=0;
		boolean f=true;
		while(f){
			f=false;
			for(int i=n-1;i>0;i--){
				int a=arr[i];
				int b=arr[i-1];
				if(a<b){
					arr[i]=b;
					arr[i-1]=a;
					count++;
					f=true;
				}
			}
			
		}
		System.out.print(arr[0]);
		for(int i=1;i<n;i++){
			System.out.print(" "+arr[i]);
		}
		System.out.println();
		System.out.println(count);
	}

}