import java.util.*;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int number = Integer.parseInt(line);
        
        int[] array = new int[number];
        String line2 = sc.nextLine();
        String[] line2sp = new String[number];
        line2sp=line2.split(" ");
        
        for(int i=0;i<number;i++){
        	array[i]=Integer.parseInt(line2sp[i]);
        }       
        
        int count=0;
        int save=-1;
        
        for(int i=0;i<number;i++){
        	for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	}
        }
        
        for(int i=0;i<number-1;i++){
        	System.out.print(array[i]+" ");
        }
        
        System.out.println(array[number-1]);
        System.out.println(count);
    }   
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int number = Integer.parseInt(line);
        
        int[] array = new int[number];
        String line2 = sc.nextLine();
        String[] line2sp = new String[number];
        line2sp=line2.split(" ");
        
        for(int i=0;i<number;i++){
        	array[i]=Integer.parseInt(line2sp[i]);
        }       
        
        int count=0;
        int save=-1;
        
        for(int i=0;i<number;i++){
        	for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	}
        }
        
        for(int i=0;i<number-1;i++){
        	System.out.print(array[i]+" ");
        }
        
        System.out.println(array[number-1]);
        System.out.println(count);
    }   
} Main public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int number = Integer.parseInt(line);
        
        int[] array = new int[number];
        String line2 = sc.nextLine();
        String[] line2sp = new String[number];
        line2sp=line2.split(" ");
        
        for(int i=0;i<number;i++){
        	array[i]=Integer.parseInt(line2sp[i]);
        }       
        
        int count=0;
        int save=-1;
        
        for(int i=0;i<number;i++){
        	for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	}
        }
        
        for(int i=0;i<number-1;i++){
        	System.out.print(array[i]+" ");
        }
        
        System.out.println(array[number-1]);
        System.out.println(count);
    } main {
    	Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int number = Integer.parseInt(line);
        
        int[] array = new int[number];
        String line2 = sc.nextLine();
        String[] line2sp = new String[number];
        line2sp=line2.split(" ");
        
        for(int i=0;i<number;i++){
        	array[i]=Integer.parseInt(line2sp[i]);
        }       
        
        int count=0;
        int save=-1;
        
        for(int i=0;i<number;i++){
        	for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	}
        }
        
        for(int i=0;i<number-1;i++){
        	System.out.print(array[i]+" ");
        }
        
        System.out.println(array[number-1]);
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String line = sc.nextLine(); line sc.nextLine() sc.nextLine sc int number = Integer.parseInt(line); number Integer.parseInt(line) Integer.parseInt Integer line int[] array = new int[number]; array new int[number] number String line2 = sc.nextLine(); line2 sc.nextLine() sc.nextLine sc String[] line2sp = new String[number]; line2sp new String[number] number line2sp=line2.split(" ") line2sp line2.split(" ") line2.split line2 " " for(int i=0;i<number;i++){
        	array[i]=Integer.parseInt(line2sp[i]);
        } int i=0; int i=0; i 0 i<number i number i++ i++ i {
        	array[i]=Integer.parseInt(line2sp[i]);
        } {
        	array[i]=Integer.parseInt(line2sp[i]);
        } array[i]=Integer.parseInt(line2sp[i]) array[i] array i Integer.parseInt(line2sp[i]) Integer.parseInt Integer line2sp[i] line2sp i int count=0; count 0 int save=-1; save -1 1 for(int i=0;i<number;i++){
        	for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	}
        } int i=0; int i=0; i 0 i<number i number i++ i++ i {
        	for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	}
        } {
        	for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	}
        } for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	} int j=0; int j=0; j 0 j<number-1 j number-1 number 1 j++ j++ j {
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	} {
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	} if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		} array[j]>array[j+1] array[j] array j array[j+1] array j+1 j 1 {
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		} save=array[j] save array[j] array j array[j]=array[j+1] array[j] array j array[j+1] array j+1 j 1 array[j+1]=save array[j+1] array j+1 j 1 save count++ count for(int i=0;i<number-1;i++){
        	System.out.print(array[i]+" ");
        } int i=0; int i=0; i 0 i<number-1 i number-1 number 1 i++ i++ i {
        	System.out.print(array[i]+" ");
        } {
        	System.out.print(array[i]+" ");
        } System.out.print(array[i]+" ") System.out.print System.out System System.out array[i]+" " array[i] array i " " System.out.println(array[number-1]) System.out.println System.out System System.out array[number-1] array number-1 number 1 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);
        String line = sc.nextLine();
        int number = Integer.parseInt(line);
        
        int[] array = new int[number];
        String line2 = sc.nextLine();
        String[] line2sp = new String[number];
        line2sp=line2.split(" ");
        
        for(int i=0;i<number;i++){
        	array[i]=Integer.parseInt(line2sp[i]);
        }       
        
        int count=0;
        int save=-1;
        
        for(int i=0;i<number;i++){
        	for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	}
        }
        
        for(int i=0;i<number-1;i++){
        	System.out.print(array[i]+" ");
        }
        
        System.out.println(array[number-1]);
        System.out.println(count);
    }   
} public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int number = Integer.parseInt(line);
        
        int[] array = new int[number];
        String line2 = sc.nextLine();
        String[] line2sp = new String[number];
        line2sp=line2.split(" ");
        
        for(int i=0;i<number;i++){
        	array[i]=Integer.parseInt(line2sp[i]);
        }       
        
        int count=0;
        int save=-1;
        
        for(int i=0;i<number;i++){
        	for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	}
        }
        
        for(int i=0;i<number-1;i++){
        	System.out.print(array[i]+" ");
        }
        
        System.out.println(array[number-1]);
        System.out.println(count);
    }   
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
        int number = Integer.parseInt(line);
        
        int[] array = new int[number];
        String line2 = sc.nextLine();
        String[] line2sp = new String[number];
        line2sp=line2.split(" ");
        
        for(int i=0;i<number;i++){
        	array[i]=Integer.parseInt(line2sp[i]);
        }       
        
        int count=0;
        int save=-1;
        
        for(int i=0;i<number;i++){
        	for(int j=0;j<number-1;j++){
        		if(array[j]>array[j+1]){
        			save=array[j];
        			array[j]=array[j+1];
        			array[j+1]=save;
        			count++;
        		}
        	}
        }
        
        for(int i=0;i<number-1;i++){
        	System.out.print(array[i]+" ");
        }
        
        System.out.println(array[number-1]);
        System.out.println(count);
    }   
}