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

public class Main {

	public static void main (String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] elements = br.readLine().split(" ");
		
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(elements[i]);
		}
		
		int swap = 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 v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			}
		}
		
		System.out.print(a[0]);	
		if(n > 1){
			for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			}
		}
		System.out.println();
		System.out.println(swap);
	}
} 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 static void main (String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] elements = br.readLine().split(" ");
		
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(elements[i]);
		}
		
		int swap = 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 v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			}
		}
		
		System.out.print(a[0]);	
		if(n > 1){
			for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			}
		}
		System.out.println();
		System.out.println(swap);
	}
} Main public static void main (String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] elements = br.readLine().split(" ");
		
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(elements[i]);
		}
		
		int swap = 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 v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			}
		}
		
		System.out.print(a[0]);	
		if(n > 1){
			for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			}
		}
		System.out.println();
		System.out.println(swap);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] elements = br.readLine().split(" ");
		
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(elements[i]);
		}
		
		int swap = 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 v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			}
		}
		
		System.out.print(a[0]);	
		if(n > 1){
			for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			}
		}
		System.out.println();
		System.out.println(swap);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] a = new int[n]; a new int[n] n String[] elements = br.readLine().split(" "); elements br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(elements[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = Integer.parseInt(elements[i]);
		} {
			a[i] = Integer.parseInt(elements[i]);
		} a[i] = Integer.parseInt(elements[i]) a[i] a i Integer.parseInt(elements[i]) Integer.parseInt Integer elements[i] elements i int swap = 0; swap 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 v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			}
		} 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 v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			}
		} {
			for(int j = a.length - 1; j >= i + 1; j--){
				if(a[j] < a[j-1]){
					int v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			}
		} for(int j = a.length - 1; j >= i + 1; j--){
				if(a[j] < a[j-1]){
					int v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			} 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 v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			} {
				if(a[j] < a[j-1]){
					int v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			} if(a[j] < a[j-1]){
					int v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				} a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 {
					int v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				} int v = a[j-1]; v a[j-1] a j-1 j 1 a[j-1] = a[j] a[j-1] a j-1 j 1 a[j] a j a[j] = v a[j] a j v swap++ swap System.out.print(a[0]) System.out.print System.out System System.out a[0] a 0 if(n > 1){
			for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			}
		} n > 1 n 1 {
			for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			}
		} for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			} int i = 1; int i = 1; i 1 i < a.length i a.length a a.length i++ i++ i {
				System.out.print(" " + a[i]);
			} {
				System.out.print(" " + a[i]);
			} System.out.print(" " + a[i]) System.out.print System.out System System.out " " + a[i] " " a[i] a i System.out.println() System.out.println System.out System System.out System.out.println(swap) System.out.println System.out System System.out swap String[] args args public class Main {

	public static void main (String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] elements = br.readLine().split(" ");
		
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(elements[i]);
		}
		
		int swap = 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 v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			}
		}
		
		System.out.print(a[0]);	
		if(n > 1){
			for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			}
		}
		System.out.println();
		System.out.println(swap);
	}
} public class Main {

	public static void main (String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] elements = br.readLine().split(" ");
		
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(elements[i]);
		}
		
		int swap = 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 v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			}
		}
		
		System.out.print(a[0]);	
		if(n > 1){
			for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			}
		}
		System.out.println();
		System.out.println(swap);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main (String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] elements = br.readLine().split(" ");
		
		for (int i = 0; i < n; i++){
			a[i] = Integer.parseInt(elements[i]);
		}
		
		int swap = 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 v = a[j-1];
					a[j-1] = a[j];
					a[j] = v;
					swap++;
				}
			}
		}
		
		System.out.print(a[0]);	
		if(n > 1){
			for (int i = 1; i < a.length; i++) {
				System.out.print(" " + a[i]);
			}
		}
		System.out.println();
		System.out.println(swap);
	}
}