import java.io.*;
import java.util.Arrays;

class Main{
    public static void main(String[] args){
	BufferedReader br
	    = new BufferedReader(new InputStreamReader(System.in), 1);
	int n;
	int[] array;
	String[] tmp = null;

	try{
	    n = Integer.parseInt(br.readLine());
	    tmp = br.readLine().split(" ");
	}catch(IOException e){
	    e.getStackTrace();
	}
	if(tmp == null)
	    System.exit(1);

	array = new int[tmp.length];
	for(int i=0; i<tmp.length; i++){
	    array[i] = Integer.parseInt(tmp[i]);
	}
	    
	
	//sort
	int t;
	int cnt = 0;
	for(int i = 0; i < array.length; i++){
	    for(int j = array.length-1; j > i; j--){
		if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		}
	    }
	}
	for(int i = 0; i < array.length; i++)
	    System.out.print(array[i] + (i != array.length-1 ? " " : "\n") );
	System.out.println(cnt);
    }
} import java.io.*; io.* java import java.util.Arrays; Arrays java.util class Main{
    public static void main(String[] args){
	BufferedReader br
	    = new BufferedReader(new InputStreamReader(System.in), 1);
	int n;
	int[] array;
	String[] tmp = null;

	try{
	    n = Integer.parseInt(br.readLine());
	    tmp = br.readLine().split(" ");
	}catch(IOException e){
	    e.getStackTrace();
	}
	if(tmp == null)
	    System.exit(1);

	array = new int[tmp.length];
	for(int i=0; i<tmp.length; i++){
	    array[i] = Integer.parseInt(tmp[i]);
	}
	    
	
	//sort
	int t;
	int cnt = 0;
	for(int i = 0; i < array.length; i++){
	    for(int j = array.length-1; j > i; j--){
		if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		}
	    }
	}
	for(int i = 0; i < array.length; i++)
	    System.out.print(array[i] + (i != array.length-1 ? " " : "\n") );
	System.out.println(cnt);
    }
} Main public static void main(String[] args){
	BufferedReader br
	    = new BufferedReader(new InputStreamReader(System.in), 1);
	int n;
	int[] array;
	String[] tmp = null;

	try{
	    n = Integer.parseInt(br.readLine());
	    tmp = br.readLine().split(" ");
	}catch(IOException e){
	    e.getStackTrace();
	}
	if(tmp == null)
	    System.exit(1);

	array = new int[tmp.length];
	for(int i=0; i<tmp.length; i++){
	    array[i] = Integer.parseInt(tmp[i]);
	}
	    
	
	//sort
	int t;
	int cnt = 0;
	for(int i = 0; i < array.length; i++){
	    for(int j = array.length-1; j > i; j--){
		if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		}
	    }
	}
	for(int i = 0; i < array.length; i++)
	    System.out.print(array[i] + (i != array.length-1 ? " " : "\n") );
	System.out.println(cnt);
    } main {
	BufferedReader br
	    = new BufferedReader(new InputStreamReader(System.in), 1);
	int n;
	int[] array;
	String[] tmp = null;

	try{
	    n = Integer.parseInt(br.readLine());
	    tmp = br.readLine().split(" ");
	}catch(IOException e){
	    e.getStackTrace();
	}
	if(tmp == null)
	    System.exit(1);

	array = new int[tmp.length];
	for(int i=0; i<tmp.length; i++){
	    array[i] = Integer.parseInt(tmp[i]);
	}
	    
	
	//sort
	int t;
	int cnt = 0;
	for(int i = 0; i < array.length; i++){
	    for(int j = array.length-1; j > i; j--){
		if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		}
	    }
	}
	for(int i = 0; i < array.length; i++)
	    System.out.print(array[i] + (i != array.length-1 ? " " : "\n") );
	System.out.println(cnt);
    } BufferedReader br
	    = new BufferedReader(new InputStreamReader(System.in), 1); br new BufferedReader(new InputStreamReader(System.in), 1) int n; n int[] array; array String[] tmp = null; tmp null try{
	    n = Integer.parseInt(br.readLine());
	    tmp = br.readLine().split(" ");
	}catch(IOException e){
	    e.getStackTrace();
	} catch(IOException e){
	    e.getStackTrace();
	} IOException e {
	    e.getStackTrace();
	} e.getStackTrace() e.getStackTrace e {
	    n = Integer.parseInt(br.readLine());
	    tmp = br.readLine().split(" ");
	} n = Integer.parseInt(br.readLine()) n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br tmp = br.readLine().split(" ") tmp br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " if(tmp == null)
	    System.exit(1); tmp == null tmp null System.exit(1) System.exit System 1 array = new int[tmp.length] array new int[tmp.length] tmp.length tmp tmp.length for(int i=0; i<tmp.length; i++){
	    array[i] = Integer.parseInt(tmp[i]);
	} int i=0; int i=0; i 0 i<tmp.length i tmp.length tmp tmp.length i++ i++ i {
	    array[i] = Integer.parseInt(tmp[i]);
	} {
	    array[i] = Integer.parseInt(tmp[i]);
	} array[i] = Integer.parseInt(tmp[i]) array[i] array i Integer.parseInt(tmp[i]) Integer.parseInt Integer tmp[i] tmp i int t; t int cnt = 0; cnt 0 for(int i = 0; i < array.length; i++){
	    for(int j = array.length-1; j > i; j--){
		if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		}
	    }
	} int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i {
	    for(int j = array.length-1; j > i; j--){
		if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		}
	    }
	} {
	    for(int j = array.length-1; j > i; j--){
		if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		}
	    }
	} for(int j = array.length-1; j > i; j--){
		if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		}
	    } int j = array.length-1; int j = array.length-1; j array.length-1 array.length array array.length 1 j > i j i j-- j-- j {
		if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		}
	    } {
		if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		}
	    } if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		} array[j] < array[j-1] array[j] array j array[j-1] array j-1 j 1 {
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		} t = array[j] t array[j] array j array[j] = array[j-1] array[j] array j array[j-1] array j-1 j 1 array[j-1] = t array[j-1] array j-1 j 1 t cnt++ cnt for(int i = 0; i < array.length; i++)
	    System.out.print(array[i] + (i != array.length-1 ? " " : "\n") ); int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i System.out.print(array[i] + (i != array.length-1 ? " " : "\n") ); System.out.print(array[i] + (i != array.length-1 ? " " : "\n") ) System.out.print System.out System System.out array[i] + (i != array.length-1 ? " " : "\n") array[i] array i (i != array.length-1 ? " " : "\n") i != array.length-1 i array.length-1 array.length array array.length 1 " " "\n" System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args
import java.io.*;
import java.util.Arrays;

class Main{
    public static void main(String[] args){
	BufferedReader br
	    = new BufferedReader(new InputStreamReader(System.in), 1);
	int n;
	int[] array;
	String[] tmp = null;

	try{
	    n = Integer.parseInt(br.readLine());
	    tmp = br.readLine().split(" ");
	}catch(IOException e){
	    e.getStackTrace();
	}
	if(tmp == null)
	    System.exit(1);

	array = new int[tmp.length];
	for(int i=0; i<tmp.length; i++){
	    array[i] = Integer.parseInt(tmp[i]);
	}
	    
	
	//sort
	int t;
	int cnt = 0;
	for(int i = 0; i < array.length; i++){
	    for(int j = array.length-1; j > i; j--){
		if( array[j] < array[j-1]){
		    t = array[j];
		    array[j] = array[j-1];
		    array[j-1] = t;
		    cnt++;
		}
	    }
	}
	for(int i = 0; i < array.length; i++)
	    System.out.print(array[i] + (i != array.length-1 ? " " : "\n") );
	System.out.println(cnt);
    }
}