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

public class Main {
	public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        int[] a = new int[n];
        String line2 = br.readLine();
        String[] str = line2.split(" ");
        for(int i=0;i<n;i++)a[i]=Integer.parseInt(str[i]);
        boolean flag=true;
        int cnt=0;
        while(flag){
        	flag=false;
        	for(int j=n-1;j>0;j--){
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	}
        }
    	for(int i=0;i<n;i++){
    		if(i!=n-1)System.out.print(a[i]+" ");
    		else System.out.println(a[i]);
    	}
    	System.out.println(cnt);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        int[] a = new int[n];
        String line2 = br.readLine();
        String[] str = line2.split(" ");
        for(int i=0;i<n;i++)a[i]=Integer.parseInt(str[i]);
        boolean flag=true;
        int cnt=0;
        while(flag){
        	flag=false;
        	for(int j=n-1;j>0;j--){
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	}
        }
    	for(int i=0;i<n;i++){
    		if(i!=n-1)System.out.print(a[i]+" ");
    		else System.out.println(a[i]);
    	}
    	System.out.println(cnt);
	}
} Main public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        int[] a = new int[n];
        String line2 = br.readLine();
        String[] str = line2.split(" ");
        for(int i=0;i<n;i++)a[i]=Integer.parseInt(str[i]);
        boolean flag=true;
        int cnt=0;
        while(flag){
        	flag=false;
        	for(int j=n-1;j>0;j--){
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	}
        }
    	for(int i=0;i<n;i++){
    		if(i!=n-1)System.out.print(a[i]+" ");
    		else System.out.println(a[i]);
    	}
    	System.out.println(cnt);
	} main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        int[] a = new int[n];
        String line2 = br.readLine();
        String[] str = line2.split(" ");
        for(int i=0;i<n;i++)a[i]=Integer.parseInt(str[i]);
        boolean flag=true;
        int cnt=0;
        while(flag){
        	flag=false;
        	for(int j=n-1;j>0;j--){
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	}
        }
    	for(int i=0;i<n;i++){
    		if(i!=n-1)System.out.print(a[i]+" ");
    		else System.out.println(a[i]);
    	}
    	System.out.println(cnt);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line = br.readLine(); line br.readLine() br.readLine br int n = Integer.parseInt(line); n Integer.parseInt(line) Integer.parseInt Integer line int[] a = new int[n]; a new int[n] n String line2 = br.readLine(); line2 br.readLine() br.readLine br String[] str = line2.split(" "); str line2.split(" ") line2.split line2 " " for(int i=0;i<n;i++)a[i]=Integer.parseInt(str[i]); int i=0; int i=0; i 0 i<n i n i++ i++ 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 boolean flag=true; flag true int cnt=0; cnt 0 while(flag){
        	flag=false;
        	for(int j=n-1;j>0;j--){
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	}
        } flag {
        	flag=false;
        	for(int j=n-1;j>0;j--){
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	}
        } flag=false flag false for(int j=n-1;j>0;j--){
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	} int j=n-1; int j=n-1; j n-1 n 1 j>0 j 0 j-- j-- j {
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	} {
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	} if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		} a[j]<a[j-1] a[j] a j a[j-1] a j-1 j 1 {
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		} int tmp = a[j]; tmp a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1]=tmp a[j-1] a j-1 j 1 tmp flag=true flag true cnt++ cnt for(int i=0;i<n;i++){
    		if(i!=n-1)System.out.print(a[i]+" ");
    		else System.out.println(a[i]);
    	} int i=0; int i=0; i 0 i<n i n i++ i++ i {
    		if(i!=n-1)System.out.print(a[i]+" ");
    		else System.out.println(a[i]);
    	} {
    		if(i!=n-1)System.out.print(a[i]+" ");
    		else System.out.println(a[i]);
    	} if(i!=n-1)System.out.print(a[i]+" ");
    		else System.out.println(a[i]); i!=n-1 i n-1 n 1 System.out.print(a[i]+" ") System.out.print System.out System System.out a[i]+" " a[i] a i " " System.out.println(a[i]) System.out.println System.out System System.out a[i] a i System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public class Main {
	public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        int[] a = new int[n];
        String line2 = br.readLine();
        String[] str = line2.split(" ");
        for(int i=0;i<n;i++)a[i]=Integer.parseInt(str[i]);
        boolean flag=true;
        int cnt=0;
        while(flag){
        	flag=false;
        	for(int j=n-1;j>0;j--){
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	}
        }
    	for(int i=0;i<n;i++){
    		if(i!=n-1)System.out.print(a[i]+" ");
    		else System.out.println(a[i]);
    	}
    	System.out.println(cnt);
	}
} public class Main {
	public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        int[] a = new int[n];
        String line2 = br.readLine();
        String[] str = line2.split(" ");
        for(int i=0;i<n;i++)a[i]=Integer.parseInt(str[i]);
        boolean flag=true;
        int cnt=0;
        while(flag){
        	flag=false;
        	for(int j=n-1;j>0;j--){
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	}
        }
    	for(int i=0;i<n;i++){
    		if(i!=n-1)System.out.print(a[i]+" ");
    		else System.out.println(a[i]);
    	}
    	System.out.println(cnt);
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int n = Integer.parseInt(line);
        int[] a = new int[n];
        String line2 = br.readLine();
        String[] str = line2.split(" ");
        for(int i=0;i<n;i++)a[i]=Integer.parseInt(str[i]);
        boolean flag=true;
        int cnt=0;
        while(flag){
        	flag=false;
        	for(int j=n-1;j>0;j--){
        		if(a[j]<a[j-1]){
        			int tmp = a[j];
        			a[j] = a[j-1];
        			a[j-1]=tmp;
        			flag=true;
        			cnt++;
        		}
        	}
        }
    	for(int i=0;i<n;i++){
    		if(i!=n-1)System.out.print(a[i]+" ");
    		else System.out.println(a[i]);
    	}
    	System.out.println(cnt);
	}
}