import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	private static void print(int[] A){
		String[] V=new String[A.length];
		for(int i=0;i<A.length;i++){
			V[i]=String.valueOf(A[i]);
		}
		System.out.println(String.join(" ",V));
	}
	
	private static void BubbleSort(int[] A){
	 int store=0;
	 for(int i = 0;i<=A.length-1;i++){
	     for(int j = A.length-1;j>=i+1;j--){
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     }
	 }
	 print(A);
	 System.out.println(store);
	}
	
	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            line=br.readLine();
            line=br.readLine();
            String[] str=line.split(" ");
            int[] A=new int[str.length];
            for(int i=0;i<A.length;i++){
            	A[i]=Integer.parseInt(str[i]);
            }
            BubbleSort(A);
        }
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	private static void print(int[] A){
		String[] V=new String[A.length];
		for(int i=0;i<A.length;i++){
			V[i]=String.valueOf(A[i]);
		}
		System.out.println(String.join(" ",V));
	}
	
	private static void BubbleSort(int[] A){
	 int store=0;
	 for(int i = 0;i<=A.length-1;i++){
	     for(int j = A.length-1;j>=i+1;j--){
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     }
	 }
	 print(A);
	 System.out.println(store);
	}
	
	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            line=br.readLine();
            line=br.readLine();
            String[] str=line.split(" ");
            int[] A=new int[str.length];
            for(int i=0;i<A.length;i++){
            	A[i]=Integer.parseInt(str[i]);
            }
            BubbleSort(A);
        }
	}
} Main private static void print(int[] A){
		String[] V=new String[A.length];
		for(int i=0;i<A.length;i++){
			V[i]=String.valueOf(A[i]);
		}
		System.out.println(String.join(" ",V));
	} print {
		String[] V=new String[A.length];
		for(int i=0;i<A.length;i++){
			V[i]=String.valueOf(A[i]);
		}
		System.out.println(String.join(" ",V));
	} String[] V=new String[A.length]; V new String[A.length] A.length A A.length for(int i=0;i<A.length;i++){
			V[i]=String.valueOf(A[i]);
		} int i=0; int i=0; i 0 i<A.length i A.length A A.length i++ i++ i {
			V[i]=String.valueOf(A[i]);
		} {
			V[i]=String.valueOf(A[i]);
		} V[i]=String.valueOf(A[i]) V[i] V i String.valueOf(A[i]) String.valueOf String A[i] A i System.out.println(String.join(" ",V)) System.out.println System.out System System.out String.join(" ",V) String.join String " " V int[] A A private static void BubbleSort(int[] A){
	 int store=0;
	 for(int i = 0;i<=A.length-1;i++){
	     for(int j = A.length-1;j>=i+1;j--){
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     }
	 }
	 print(A);
	 System.out.println(store);
	} BubbleSort {
	 int store=0;
	 for(int i = 0;i<=A.length-1;i++){
	     for(int j = A.length-1;j>=i+1;j--){
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     }
	 }
	 print(A);
	 System.out.println(store);
	} int store=0; store 0 for(int i = 0;i<=A.length-1;i++){
	     for(int j = A.length-1;j>=i+1;j--){
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     }
	 } int i = 0; int i = 0; i 0 i<=A.length-1 i A.length-1 A.length A A.length 1 i++ i++ i {
	     for(int j = A.length-1;j>=i+1;j--){
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     }
	 } {
	     for(int j = A.length-1;j>=i+1;j--){
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     }
	 } for(int j = A.length-1;j>=i+1;j--){
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     } 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 w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     } {
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     } if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         } A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 {
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         } int w=A[j]; w A[j] A j A[j]=A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1]=w A[j-1] A j-1 j 1 w store++ store print(A) print A System.out.println(store) System.out.println System.out System System.out store int[] A A public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            line=br.readLine();
            line=br.readLine();
            String[] str=line.split(" ");
            int[] A=new int[str.length];
            for(int i=0;i<A.length;i++){
            	A[i]=Integer.parseInt(str[i]);
            }
            BubbleSort(A);
        }
	} main {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            line=br.readLine();
            line=br.readLine();
            String[] str=line.split(" ");
            int[] A=new int[str.length];
            for(int i=0;i<A.length;i++){
            	A[i]=Integer.parseInt(str[i]);
            }
            BubbleSort(A);
        }
	} try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            line=br.readLine();
            line=br.readLine();
            String[] str=line.split(" ");
            int[] A=new int[str.length];
            for(int i=0;i<A.length;i++){
            	A[i]=Integer.parseInt(str[i]);
            }
            BubbleSort(A);
        } {
            String line;
            line=br.readLine();
            line=br.readLine();
            String[] str=line.split(" ");
            int[] A=new int[str.length];
            for(int i=0;i<A.length;i++){
            	A[i]=Integer.parseInt(str[i]);
            }
            BubbleSort(A);
        } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) BufferedReader br = new BufferedReader(new InputStreamReader(System.in)) new BufferedReader(new InputStreamReader(System.in)) String line; line line=br.readLine() line br.readLine() br.readLine br line=br.readLine() line br.readLine() br.readLine br String[] str=line.split(" "); str line.split(" ") line.split line " " int[] A=new int[str.length]; A new int[str.length] str.length str str.length for(int i=0;i<A.length;i++){
            	A[i]=Integer.parseInt(str[i]);
            } int i=0; int i=0; i 0 i<A.length i A.length A A.length i++ i++ i {
            	A[i]=Integer.parseInt(str[i]);
            } {
            	A[i]=Integer.parseInt(str[i]);
            } A[i]=Integer.parseInt(str[i]) A[i] A i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i BubbleSort(A) BubbleSort A String[] args args public class Main {
	private static void print(int[] A){
		String[] V=new String[A.length];
		for(int i=0;i<A.length;i++){
			V[i]=String.valueOf(A[i]);
		}
		System.out.println(String.join(" ",V));
	}
	
	private static void BubbleSort(int[] A){
	 int store=0;
	 for(int i = 0;i<=A.length-1;i++){
	     for(int j = A.length-1;j>=i+1;j--){
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     }
	 }
	 print(A);
	 System.out.println(store);
	}
	
	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            line=br.readLine();
            line=br.readLine();
            String[] str=line.split(" ");
            int[] A=new int[str.length];
            for(int i=0;i<A.length;i++){
            	A[i]=Integer.parseInt(str[i]);
            }
            BubbleSort(A);
        }
	}
} public class Main {
	private static void print(int[] A){
		String[] V=new String[A.length];
		for(int i=0;i<A.length;i++){
			V[i]=String.valueOf(A[i]);
		}
		System.out.println(String.join(" ",V));
	}
	
	private static void BubbleSort(int[] A){
	 int store=0;
	 for(int i = 0;i<=A.length-1;i++){
	     for(int j = A.length-1;j>=i+1;j--){
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     }
	 }
	 print(A);
	 System.out.println(store);
	}
	
	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            line=br.readLine();
            line=br.readLine();
            String[] str=line.split(" ");
            int[] A=new int[str.length];
            for(int i=0;i<A.length;i++){
            	A[i]=Integer.parseInt(str[i]);
            }
            BubbleSort(A);
        }
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	private static void print(int[] A){
		String[] V=new String[A.length];
		for(int i=0;i<A.length;i++){
			V[i]=String.valueOf(A[i]);
		}
		System.out.println(String.join(" ",V));
	}
	
	private static void BubbleSort(int[] A){
	 int store=0;
	 for(int i = 0;i<=A.length-1;i++){
	     for(int j = A.length-1;j>=i+1;j--){
	         if(A[j] < A[j-1]){
	             int w=A[j];
	             A[j]=A[j-1];
	             A[j-1]=w;
	             store++;
	         }
	     }
	 }
	 print(A);
	 System.out.println(store);
	}
	
	public static void main(String[] args) throws Exception {
        // TODO ?????????????????????????????????????????????
        
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            String line;
            line=br.readLine();
            line=br.readLine();
            String[] str=line.split(" ");
            int[] A=new int[str.length];
            for(int i=0;i<A.length;i++){
            	A[i]=Integer.parseInt(str[i]);
            }
            BubbleSort(A);
        }
	}
}