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

public class Main {

	public void Sort(){

	}

	public void maain(){

	}

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????

		//1???????????\????????¢
	       StringBuilder buider = new StringBuilder();

	       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String n = br.readLine();
        int count = 0;
        int yard = 0;

        //
        int[] num = new int[Integer.parseInt(n)];

        String[] input2 = br.readLine().split(" ");

        for(int i = 0; i < num.length; i++){
        	num[i] = Integer.parseInt(input2[i]);
        }

        //
        for(int i = 0; i < num.length ; i++){

        	for(int j = num.length - 1 ; i + 1 <= j; j--){
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	}
        }

        //
        for(int i = 0; i < num.length; i++){

        	if(i == num.length - 1){
        		System.out.println(num[i]);
        		System.out.println(count);
        	}else{
            	System.out.print(num[i] + " ");
        	}
        }
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public void Sort(){

	}

	public void maain(){

	}

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????

		//1???????????\????????¢
	       StringBuilder buider = new StringBuilder();

	       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String n = br.readLine();
        int count = 0;
        int yard = 0;

        //
        int[] num = new int[Integer.parseInt(n)];

        String[] input2 = br.readLine().split(" ");

        for(int i = 0; i < num.length; i++){
        	num[i] = Integer.parseInt(input2[i]);
        }

        //
        for(int i = 0; i < num.length ; i++){

        	for(int j = num.length - 1 ; i + 1 <= j; j--){
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	}
        }

        //
        for(int i = 0; i < num.length; i++){

        	if(i == num.length - 1){
        		System.out.println(num[i]);
        		System.out.println(count);
        	}else{
            	System.out.print(num[i] + " ");
        	}
        }
	}
} Main public void Sort(){

	} Sort {

	} public void maain(){

	} maain {

	} public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????

		//1???????????\????????¢
	       StringBuilder buider = new StringBuilder();

	       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String n = br.readLine();
        int count = 0;
        int yard = 0;

        //
        int[] num = new int[Integer.parseInt(n)];

        String[] input2 = br.readLine().split(" ");

        for(int i = 0; i < num.length; i++){
        	num[i] = Integer.parseInt(input2[i]);
        }

        //
        for(int i = 0; i < num.length ; i++){

        	for(int j = num.length - 1 ; i + 1 <= j; j--){
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	}
        }

        //
        for(int i = 0; i < num.length; i++){

        	if(i == num.length - 1){
        		System.out.println(num[i]);
        		System.out.println(count);
        	}else{
            	System.out.print(num[i] + " ");
        	}
        }
	} main {
		// TODO ?????????????????????????????????????????????

		//1???????????\????????¢
	       StringBuilder buider = new StringBuilder();

	       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String n = br.readLine();
        int count = 0;
        int yard = 0;

        //
        int[] num = new int[Integer.parseInt(n)];

        String[] input2 = br.readLine().split(" ");

        for(int i = 0; i < num.length; i++){
        	num[i] = Integer.parseInt(input2[i]);
        }

        //
        for(int i = 0; i < num.length ; i++){

        	for(int j = num.length - 1 ; i + 1 <= j; j--){
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	}
        }

        //
        for(int i = 0; i < num.length; i++){

        	if(i == num.length - 1){
        		System.out.println(num[i]);
        		System.out.println(count);
        	}else{
            	System.out.print(num[i] + " ");
        	}
        }
	} StringBuilder buider = new StringBuilder(); buider new StringBuilder() BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String n = br.readLine(); n br.readLine() br.readLine br int count = 0; count 0 int yard = 0; yard 0 int[] num = new int[Integer.parseInt(n)]; num new int[Integer.parseInt(n)] Integer.parseInt(n) Integer.parseInt Integer n String[] input2 = br.readLine().split(" "); input2 br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int i = 0; i < num.length; i++){
        	num[i] = Integer.parseInt(input2[i]);
        } int i = 0; int i = 0; i 0 i < num.length i num.length num num.length i++ i++ i {
        	num[i] = Integer.parseInt(input2[i]);
        } {
        	num[i] = Integer.parseInt(input2[i]);
        } num[i] = Integer.parseInt(input2[i]) num[i] num i Integer.parseInt(input2[i]) Integer.parseInt Integer input2[i] input2 i for(int i = 0; i < num.length ; i++){

        	for(int j = num.length - 1 ; i + 1 <= j; j--){
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	}
        } int i = 0; int i = 0; i 0 i < num.length i num.length num num.length i++ i++ i {

        	for(int j = num.length - 1 ; i + 1 <= j; j--){
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	}
        } {

        	for(int j = num.length - 1 ; i + 1 <= j; j--){
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	}
        } for(int j = num.length - 1 ; i + 1 <= j; j--){
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	} int j = num.length - 1 ; int j = num.length - 1 ; j num.length - 1 num.length num num.length 1 i + 1 <= j i + 1 i 1 j j-- j-- j {
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	} {
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	} if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		} num[j] < num[j - 1] num[j] num j num[j - 1] num j - 1 j 1 {

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		} count++ count yard = num[j] yard num[j] num j num[j] = num[j - 1] num[j] num j num[j - 1] num j - 1 j 1 num[j - 1] = yard num[j - 1] num j - 1 j 1 yard for(int i = 0; i < num.length; i++){

        	if(i == num.length - 1){
        		System.out.println(num[i]);
        		System.out.println(count);
        	}else{
            	System.out.print(num[i] + " ");
        	}
        } int i = 0; int i = 0; i 0 i < num.length i num.length num num.length i++ i++ i {

        	if(i == num.length - 1){
        		System.out.println(num[i]);
        		System.out.println(count);
        	}else{
            	System.out.print(num[i] + " ");
        	}
        } {

        	if(i == num.length - 1){
        		System.out.println(num[i]);
        		System.out.println(count);
        	}else{
            	System.out.print(num[i] + " ");
        	}
        } if(i == num.length - 1){
        		System.out.println(num[i]);
        		System.out.println(count);
        	}else{
            	System.out.print(num[i] + " ");
        	} i == num.length - 1 i num.length - 1 num.length num num.length 1 {
        		System.out.println(num[i]);
        		System.out.println(count);
        	} System.out.println(num[i]) System.out.println System.out System System.out num[i] num i System.out.println(count) System.out.println System.out System System.out count {
            	System.out.print(num[i] + " ");
        	} System.out.print(num[i] + " ") System.out.print System.out System System.out num[i] + " " num[i] num i " " String[] args args public class Main {

	public void Sort(){

	}

	public void maain(){

	}

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????

		//1???????????\????????¢
	       StringBuilder buider = new StringBuilder();

	       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String n = br.readLine();
        int count = 0;
        int yard = 0;

        //
        int[] num = new int[Integer.parseInt(n)];

        String[] input2 = br.readLine().split(" ");

        for(int i = 0; i < num.length; i++){
        	num[i] = Integer.parseInt(input2[i]);
        }

        //
        for(int i = 0; i < num.length ; i++){

        	for(int j = num.length - 1 ; i + 1 <= j; j--){
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	}
        }

        //
        for(int i = 0; i < num.length; i++){

        	if(i == num.length - 1){
        		System.out.println(num[i]);
        		System.out.println(count);
        	}else{
            	System.out.print(num[i] + " ");
        	}
        }
	}
} public class Main {

	public void Sort(){

	}

	public void maain(){

	}

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????

		//1???????????\????????¢
	       StringBuilder buider = new StringBuilder();

	       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String n = br.readLine();
        int count = 0;
        int yard = 0;

        //
        int[] num = new int[Integer.parseInt(n)];

        String[] input2 = br.readLine().split(" ");

        for(int i = 0; i < num.length; i++){
        	num[i] = Integer.parseInt(input2[i]);
        }

        //
        for(int i = 0; i < num.length ; i++){

        	for(int j = num.length - 1 ; i + 1 <= j; j--){
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	}
        }

        //
        for(int i = 0; i < num.length; i++){

        	if(i == num.length - 1){
        		System.out.println(num[i]);
        		System.out.println(count);
        	}else{
            	System.out.print(num[i] + " ");
        	}
        }
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public void Sort(){

	}

	public void maain(){

	}

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????

		//1???????????\????????¢
	       StringBuilder buider = new StringBuilder();

	       BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        String n = br.readLine();
        int count = 0;
        int yard = 0;

        //
        int[] num = new int[Integer.parseInt(n)];

        String[] input2 = br.readLine().split(" ");

        for(int i = 0; i < num.length; i++){
        	num[i] = Integer.parseInt(input2[i]);
        }

        //
        for(int i = 0; i < num.length ; i++){

        	for(int j = num.length - 1 ; i + 1 <= j; j--){
    			
        		if(num[j] < num[j - 1]){

        			count++;
        			yard = num[j];
        			num[j] = num[j - 1];
        			num[j - 1] = yard;
        		}
        	}
        }

        //
        for(int i = 0; i < num.length; i++){

        	if(i == num.length - 1){
        		System.out.println(num[i]);
        		System.out.println(count);
        	}else{
            	System.out.print(num[i] + " ");
        	}
        }
	}
}