import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
  
public class Main {
    private static final String CRLF = System.lineSeparator();
    public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
        int count=0;
        int N = in.readInt();
        int[] A = in.readIntArray(N);
        int tmp;
        for(boolean flag=true;flag;){
        	flag=false;
        	for(int j=N-1;j>=1;j--){
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	}
        }
        intArrayToString(A,sb);
        out.print(sb.toString());
        out.println(count);
        out.flush();
    }
    
    private void intArrayToString(int[] a, StringBuilder sb) {
        for(int i=0; i<a.length; i++) {
            if (i>0)
                sb.append(" ");
            sb.append(a[i]);
        }
        sb.append(CRLF);
    }
     
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
}

class SimpleInputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public int readInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }
    public int[] readIntArray(int len) throws NumberFormatException, IOException{
        int[] a = new int[len];
        int i=0;
        for(String s: br.readLine().split(" ")){
            a[i++] = Integer.parseInt(s);
        }
        return a;
    }
    
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.PrintWriter; PrintWriter java.io public class Main {
    private static final String CRLF = System.lineSeparator();
    public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
        int count=0;
        int N = in.readInt();
        int[] A = in.readIntArray(N);
        int tmp;
        for(boolean flag=true;flag;){
        	flag=false;
        	for(int j=N-1;j>=1;j--){
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	}
        }
        intArrayToString(A,sb);
        out.print(sb.toString());
        out.println(count);
        out.flush();
    }
    
    private void intArrayToString(int[] a, StringBuilder sb) {
        for(int i=0; i<a.length; i++) {
            if (i>0)
                sb.append(" ");
            sb.append(a[i]);
        }
        sb.append(CRLF);
    }
     
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
} Main private static final String CRLF = System.lineSeparator(); CRLF System.lineSeparator() System.lineSeparator System public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
        int count=0;
        int N = in.readInt();
        int[] A = in.readIntArray(N);
        int tmp;
        for(boolean flag=true;flag;){
        	flag=false;
        	for(int j=N-1;j>=1;j--){
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	}
        }
        intArrayToString(A,sb);
        out.print(sb.toString());
        out.println(count);
        out.flush();
    } exec {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
        int count=0;
        int N = in.readInt();
        int[] A = in.readIntArray(N);
        int tmp;
        for(boolean flag=true;flag;){
        	flag=false;
        	for(int j=N-1;j>=1;j--){
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	}
        }
        intArrayToString(A,sb);
        out.print(sb.toString());
        out.println(count);
        out.flush();
    } SimpleInputUtil in = new SimpleInputUtil(); in new SimpleInputUtil() PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int count=0; count 0 int N = in.readInt(); N in.readInt() in.readInt in int[] A = in.readIntArray(N); A in.readIntArray(N) in.readIntArray in N int tmp; tmp for(boolean flag=true;flag;){
        	flag=false;
        	for(int j=N-1;j>=1;j--){
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	}
        } boolean flag=true; boolean flag=true; flag true flag {
        	flag=false;
        	for(int j=N-1;j>=1;j--){
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	}
        } {
        	flag=false;
        	for(int j=N-1;j>=1;j--){
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	}
        } flag=false flag false for(int j=N-1;j>=1;j--){
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	} int j=N-1; int j=N-1; j N-1 N 1 j>=1 j 1 j-- j-- j {
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	} {
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	} if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		} A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 {
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		} 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 count++ count flag=true flag true intArrayToString(A,sb) intArrayToString A sb out.print(sb.toString()) out.print out sb.toString() sb.toString sb out.println(count) out.println out count out.flush() out.flush out private void intArrayToString(int[] a, StringBuilder sb) {
        for(int i=0; i<a.length; i++) {
            if (i>0)
                sb.append(" ");
            sb.append(a[i]);
        }
        sb.append(CRLF);
    } intArrayToString {
        for(int i=0; i<a.length; i++) {
            if (i>0)
                sb.append(" ");
            sb.append(a[i]);
        }
        sb.append(CRLF);
    } for(int i=0; i<a.length; i++) {
            if (i>0)
                sb.append(" ");
            sb.append(a[i]);
        } int i=0; int i=0; i 0 i<a.length i a.length a a.length i++ i++ i {
            if (i>0)
                sb.append(" ");
            sb.append(a[i]);
        } {
            if (i>0)
                sb.append(" ");
            sb.append(a[i]);
        } if (i>0)
                sb.append(" "); i>0 i 0 sb.append(" ") sb.append sb " " sb.append(a[i]) sb.append sb a[i] a i sb.append(CRLF) sb.append sb CRLF int[] a a StringBuilder sb sb public static void main(String[] args) throws IOException {
        new Main().exec();
    } main {
        new Main().exec();
    } new Main().exec() new Main().exec new Main() String[] args args class SimpleInputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public int readInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }
    public int[] readIntArray(int len) throws NumberFormatException, IOException{
        int[] a = new int[len];
        int i=0;
        for(String s: br.readLine().split(" ")){
            a[i++] = Integer.parseInt(s);
        }
        return a;
    }
    
} SimpleInputUtil BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) public int readInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    } readInt {
    	return Integer.parseInt(br.readLine());
    } return Integer.parseInt(br.readLine()); Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br public int[] readIntArray(int len) throws NumberFormatException, IOException{
        int[] a = new int[len];
        int i=0;
        for(String s: br.readLine().split(" ")){
            a[i++] = Integer.parseInt(s);
        }
        return a;
    } readIntArray {
        int[] a = new int[len];
        int i=0;
        for(String s: br.readLine().split(" ")){
            a[i++] = Integer.parseInt(s);
        }
        return a;
    } int[] a = new int[len]; a new int[len] len int i=0; i 0 for(String s: br.readLine().split(" ")){
            a[i++] = Integer.parseInt(s);
        } String s br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " {
            a[i++] = Integer.parseInt(s);
        } {
            a[i++] = Integer.parseInt(s);
        } a[i++] = Integer.parseInt(s) a[i++] a i++ i Integer.parseInt(s) Integer.parseInt Integer s return a; a int len len public class Main {
    private static final String CRLF = System.lineSeparator();
    public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
        int count=0;
        int N = in.readInt();
        int[] A = in.readIntArray(N);
        int tmp;
        for(boolean flag=true;flag;){
        	flag=false;
        	for(int j=N-1;j>=1;j--){
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	}
        }
        intArrayToString(A,sb);
        out.print(sb.toString());
        out.println(count);
        out.flush();
    }
    
    private void intArrayToString(int[] a, StringBuilder sb) {
        for(int i=0; i<a.length; i++) {
            if (i>0)
                sb.append(" ");
            sb.append(a[i]);
        }
        sb.append(CRLF);
    }
     
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
} public class Main {
    private static final String CRLF = System.lineSeparator();
    public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
        int count=0;
        int N = in.readInt();
        int[] A = in.readIntArray(N);
        int tmp;
        for(boolean flag=true;flag;){
        	flag=false;
        	for(int j=N-1;j>=1;j--){
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	}
        }
        intArrayToString(A,sb);
        out.print(sb.toString());
        out.println(count);
        out.flush();
    }
    
    private void intArrayToString(int[] a, StringBuilder sb) {
        for(int i=0; i<a.length; i++) {
            if (i>0)
                sb.append(" ");
            sb.append(a[i]);
        }
        sb.append(CRLF);
    }
     
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
  
public class Main {
    private static final String CRLF = System.lineSeparator();
    public void exec() throws IOException {
    	SimpleInputUtil in = new SimpleInputUtil();
        PrintWriter out = new PrintWriter(System.out);
        StringBuilder sb = new StringBuilder();
        int count=0;
        int N = in.readInt();
        int[] A = in.readIntArray(N);
        int tmp;
        for(boolean flag=true;flag;){
        	flag=false;
        	for(int j=N-1;j>=1;j--){
        		if(A[j] < A[j-1]){
        			tmp = A[j];
        			A[j] = A[j-1];
        			A[j-1] = tmp;
        			count++;
        			flag=true;
        		}
        	}
        }
        intArrayToString(A,sb);
        out.print(sb.toString());
        out.println(count);
        out.flush();
    }
    
    private void intArrayToString(int[] a, StringBuilder sb) {
        for(int i=0; i<a.length; i++) {
            if (i>0)
                sb.append(" ");
            sb.append(a[i]);
        }
        sb.append(CRLF);
    }
     
    public static void main(String[] args) throws IOException {
        new Main().exec();
    }
}

class SimpleInputUtil {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public int readInt() throws NumberFormatException, IOException{
    	return Integer.parseInt(br.readLine());
    }
    public int[] readIntArray(int len) throws NumberFormatException, IOException{
        int[] a = new int[len];
        int i=0;
        for(String s: br.readLine().split(" ")){
            a[i++] = Integer.parseInt(s);
        }
        return a;
    }
    
}