
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	static int cnt = 0;
	static PrintWriter out =new PrintWriter(System.out);
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	int n = sc.nextInt();
    	int array[] = new int[n];
    	for(int i=0;i<n;i++) {
    		array[i] = sc.nextInt();
    	}
    	bubble(array);
    	out.print(array[0]);
    	for(int i=1;i<n;i++) {
    		out.print(" "+array[i]);
    	}
    	out.println();
    	out.println(cnt);
    	out.flush();
    }
    
    static void bubble(int[] a) {
    	for(int i=0;i<a.length;i++) {
    		for(int j=a.length-1;j>=i+1;j--) {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		}
    	}
    }
    	
} import java.io.PrintWriter; PrintWriter java.io import java.util.Scanner; Scanner java.util public class Main {
	static int cnt = 0;
	static PrintWriter out =new PrintWriter(System.out);
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	int n = sc.nextInt();
    	int array[] = new int[n];
    	for(int i=0;i<n;i++) {
    		array[i] = sc.nextInt();
    	}
    	bubble(array);
    	out.print(array[0]);
    	for(int i=1;i<n;i++) {
    		out.print(" "+array[i]);
    	}
    	out.println();
    	out.println(cnt);
    	out.flush();
    }
    
    static void bubble(int[] a) {
    	for(int i=0;i<a.length;i++) {
    		for(int j=a.length-1;j>=i+1;j--) {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		}
    	}
    }
    	
} Main static int cnt = 0; cnt 0 static PrintWriter out =new PrintWriter(System.out); out new PrintWriter(System.out) public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	int n = sc.nextInt();
    	int array[] = new int[n];
    	for(int i=0;i<n;i++) {
    		array[i] = sc.nextInt();
    	}
    	bubble(array);
    	out.print(array[0]);
    	for(int i=1;i<n;i++) {
    		out.print(" "+array[i]);
    	}
    	out.println();
    	out.println(cnt);
    	out.flush();
    } main {
    	Scanner sc = new Scanner(System.in);
    	
    	int n = sc.nextInt();
    	int array[] = new int[n];
    	for(int i=0;i<n;i++) {
    		array[i] = sc.nextInt();
    	}
    	bubble(array);
    	out.print(array[0]);
    	for(int i=1;i<n;i++) {
    		out.print(" "+array[i]);
    	}
    	out.println();
    	out.println(cnt);
    	out.flush();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int array[] = new int[n]; array new int[n] n for(int i=0;i<n;i++) {
    		array[i] = sc.nextInt();
    	} int i=0; int i=0; i 0 i<n i n i++ i++ i {
    		array[i] = sc.nextInt();
    	} {
    		array[i] = sc.nextInt();
    	} array[i] = sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc bubble(array) bubble array out.print(array[0]) out.print out array[0] array 0 for(int i=1;i<n;i++) {
    		out.print(" "+array[i]);
    	} int i=1; int i=1; i 1 i<n i n i++ i++ i {
    		out.print(" "+array[i]);
    	} {
    		out.print(" "+array[i]);
    	} out.print(" "+array[i]) out.print out " "+array[i] " " array[i] array i out.println() out.println out out.println(cnt) out.println out cnt out.flush() out.flush out String[] args args static void bubble(int[] a) {
    	for(int i=0;i<a.length;i++) {
    		for(int j=a.length-1;j>=i+1;j--) {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		}
    	}
    } bubble {
    	for(int i=0;i<a.length;i++) {
    		for(int j=a.length-1;j>=i+1;j--) {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		}
    	}
    } for(int i=0;i<a.length;i++) {
    		for(int j=a.length-1;j>=i+1;j--) {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		}
    	} 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+1;j--) {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		}
    	} {
    		for(int j=a.length-1;j>=i+1;j--) {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		}
    	} for(int j=a.length-1;j>=i+1;j--) {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		} int j=a.length-1; int j=a.length-1; j a.length-1 a.length a a.length 1 j>=i+1 j i+1 i 1 j-- j-- j {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		} {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		} if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			} a[j]<a[j-1] a[j] a j a[j-1] a j-1 j 1 {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			} int temp = a[j]; temp a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1] =temp a[j-1] a j-1 j 1 temp cnt++ cnt int[] a a public class Main {
	static int cnt = 0;
	static PrintWriter out =new PrintWriter(System.out);
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	int n = sc.nextInt();
    	int array[] = new int[n];
    	for(int i=0;i<n;i++) {
    		array[i] = sc.nextInt();
    	}
    	bubble(array);
    	out.print(array[0]);
    	for(int i=1;i<n;i++) {
    		out.print(" "+array[i]);
    	}
    	out.println();
    	out.println(cnt);
    	out.flush();
    }
    
    static void bubble(int[] a) {
    	for(int i=0;i<a.length;i++) {
    		for(int j=a.length-1;j>=i+1;j--) {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		}
    	}
    }
    	
} public class Main {
	static int cnt = 0;
	static PrintWriter out =new PrintWriter(System.out);
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	int n = sc.nextInt();
    	int array[] = new int[n];
    	for(int i=0;i<n;i++) {
    		array[i] = sc.nextInt();
    	}
    	bubble(array);
    	out.print(array[0]);
    	for(int i=1;i<n;i++) {
    		out.print(" "+array[i]);
    	}
    	out.println();
    	out.println(cnt);
    	out.flush();
    }
    
    static void bubble(int[] a) {
    	for(int i=0;i<a.length;i++) {
    		for(int j=a.length-1;j>=i+1;j--) {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		}
    	}
    }
    	
} Main

import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	static int cnt = 0;
	static PrintWriter out =new PrintWriter(System.out);
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	
    	int n = sc.nextInt();
    	int array[] = new int[n];
    	for(int i=0;i<n;i++) {
    		array[i] = sc.nextInt();
    	}
    	bubble(array);
    	out.print(array[0]);
    	for(int i=1;i<n;i++) {
    		out.print(" "+array[i]);
    	}
    	out.println();
    	out.println(cnt);
    	out.flush();
    }
    
    static void bubble(int[] a) {
    	for(int i=0;i<a.length;i++) {
    		for(int j=a.length-1;j>=i+1;j--) {
    			if(a[j]<a[j-1]) {
    				int temp = a[j];
    				a[j] = a[j-1];
    				a[j-1] =temp;
    				cnt++;
    			}
    				
    		}
    	}
    }
    	
}
