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

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

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

		try {
			int N = Integer.parseInt(br.readLine());
			if(N == 1){
				System.out.println(br.readLine());
				System.out.println(0);
				return;
			}


			String tmp_str[] = br.readLine().split("\\s+");
			int array[] = new int[N];

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

			int swap_count = 0,work;

			for(int i = 0; i < N-1; i++){
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			}

			StringBuilder sb = new StringBuilder();
			sb.append(Integer.toBinaryString(array[0]));
			for(int i = 1; i < array.length; i++){
				sb.append(" ").append(Integer.toString(array[i]));
			}
			System.out.println(sb.toString());
			System.out.println(swap_count);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
 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 final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

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

		try {
			int N = Integer.parseInt(br.readLine());
			if(N == 1){
				System.out.println(br.readLine());
				System.out.println(0);
				return;
			}


			String tmp_str[] = br.readLine().split("\\s+");
			int array[] = new int[N];

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

			int swap_count = 0,work;

			for(int i = 0; i < N-1; i++){
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			}

			StringBuilder sb = new StringBuilder();
			sb.append(Integer.toBinaryString(array[0]));
			for(int i = 1; i < array.length; i++){
				sb.append(" ").append(Integer.toString(array[i]));
			}
			System.out.println(sb.toString());
			System.out.println(swap_count);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
} Main public static final int BIG_NUM  = 2000000000; BIG_NUM 2000000000 public static final int MOD  = 1000000007; MOD 1000000007 public static void main(String[] args) {

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

		try {
			int N = Integer.parseInt(br.readLine());
			if(N == 1){
				System.out.println(br.readLine());
				System.out.println(0);
				return;
			}


			String tmp_str[] = br.readLine().split("\\s+");
			int array[] = new int[N];

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

			int swap_count = 0,work;

			for(int i = 0; i < N-1; i++){
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			}

			StringBuilder sb = new StringBuilder();
			sb.append(Integer.toBinaryString(array[0]));
			for(int i = 1; i < array.length; i++){
				sb.append(" ").append(Integer.toString(array[i]));
			}
			System.out.println(sb.toString());
			System.out.println(swap_count);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	} main {

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

		try {
			int N = Integer.parseInt(br.readLine());
			if(N == 1){
				System.out.println(br.readLine());
				System.out.println(0);
				return;
			}


			String tmp_str[] = br.readLine().split("\\s+");
			int array[] = new int[N];

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

			int swap_count = 0,work;

			for(int i = 0; i < N-1; i++){
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			}

			StringBuilder sb = new StringBuilder();
			sb.append(Integer.toBinaryString(array[0]));
			for(int i = 1; i < array.length; i++){
				sb.append(" ").append(Integer.toString(array[i]));
			}
			System.out.println(sb.toString());
			System.out.println(swap_count);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {
			int N = Integer.parseInt(br.readLine());
			if(N == 1){
				System.out.println(br.readLine());
				System.out.println(0);
				return;
			}


			String tmp_str[] = br.readLine().split("\\s+");
			int array[] = new int[N];

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

			int swap_count = 0,work;

			for(int i = 0; i < N-1; i++){
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			}

			StringBuilder sb = new StringBuilder();
			sb.append(Integer.toBinaryString(array[0]));
			for(int i = 1; i < array.length; i++){
				sb.append(" ").append(Integer.toString(array[i]));
			}
			System.out.println(sb.toString());
			System.out.println(swap_count);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (NumberFormatException e) {
			e.printStackTrace();
		} NumberFormatException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			int N = Integer.parseInt(br.readLine());
			if(N == 1){
				System.out.println(br.readLine());
				System.out.println(0);
				return;
			}


			String tmp_str[] = br.readLine().split("\\s+");
			int array[] = new int[N];

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

			int swap_count = 0,work;

			for(int i = 0; i < N-1; i++){
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			}

			StringBuilder sb = new StringBuilder();
			sb.append(Integer.toBinaryString(array[0]));
			for(int i = 1; i < array.length; i++){
				sb.append(" ").append(Integer.toString(array[i]));
			}
			System.out.println(sb.toString());
			System.out.println(swap_count);

		} int N = Integer.parseInt(br.readLine()); N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br if(N == 1){
				System.out.println(br.readLine());
				System.out.println(0);
				return;
			} N == 1 N 1 {
				System.out.println(br.readLine());
				System.out.println(0);
				return;
			} System.out.println(br.readLine()) System.out.println System.out System System.out br.readLine() br.readLine br System.out.println(0) System.out.println System.out System System.out 0 return; String tmp_str[] = br.readLine().split("\\s+"); tmp_str br.readLine().split("\\s+") br.readLine().split br.readLine() br.readLine br "\\s+" int array[] = new int[N]; array new int[N] N for(int i = 0; i < tmp_str.length; i++){
				array[i] = Integer.parseInt(tmp_str[i]);
			} int i = 0; int i = 0; i 0 i < tmp_str.length i tmp_str.length tmp_str tmp_str.length i++ i++ i {
				array[i] = Integer.parseInt(tmp_str[i]);
			} {
				array[i] = Integer.parseInt(tmp_str[i]);
			} array[i] = Integer.parseInt(tmp_str[i]) array[i] array i Integer.parseInt(tmp_str[i]) Integer.parseInt Integer tmp_str[i] tmp_str i int swap_count = 0 swap_count 0 work; work for(int i = 0; i < N-1; i++){
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			} int i = 0; int i = 0; i 0 i < N-1 i N-1 N 1 i++ i++ i {
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			} {
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			} for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				} int k = N-1; int k = N-1; k N-1 N 1 k >= i+1 k i+1 i 1 k-- k-- k {
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				} {
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				} if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					} array[k] < array[k-1] array[k] array k array[k-1] array k-1 k 1 {
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					} work = array[k-1] work array[k-1] array k-1 k 1 array[k-1] = array[k] array[k-1] array k-1 k 1 array[k] array k array[k] = work array[k] array k work swap_count++ swap_count StringBuilder sb = new StringBuilder(); sb new StringBuilder() sb.append(Integer.toBinaryString(array[0])) sb.append sb Integer.toBinaryString(array[0]) Integer.toBinaryString Integer array[0] array 0 for(int i = 1; i < array.length; i++){
				sb.append(" ").append(Integer.toString(array[i]));
			} int i = 1; int i = 1; i 1 i < array.length i array.length array array.length i++ i++ i {
				sb.append(" ").append(Integer.toString(array[i]));
			} {
				sb.append(" ").append(Integer.toString(array[i]));
			} sb.append(" ").append(Integer.toString(array[i])) sb.append(" ").append sb.append(" ") sb.append sb " " Integer.toString(array[i]) Integer.toString Integer array[i] array i System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb System.out.println(swap_count) System.out.println System.out System System.out swap_count String[] args args public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

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

		try {
			int N = Integer.parseInt(br.readLine());
			if(N == 1){
				System.out.println(br.readLine());
				System.out.println(0);
				return;
			}


			String tmp_str[] = br.readLine().split("\\s+");
			int array[] = new int[N];

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

			int swap_count = 0,work;

			for(int i = 0; i < N-1; i++){
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			}

			StringBuilder sb = new StringBuilder();
			sb.append(Integer.toBinaryString(array[0]));
			for(int i = 1; i < array.length; i++){
				sb.append(" ").append(Integer.toString(array[i]));
			}
			System.out.println(sb.toString());
			System.out.println(swap_count);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
} public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

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

		try {
			int N = Integer.parseInt(br.readLine());
			if(N == 1){
				System.out.println(br.readLine());
				System.out.println(0);
				return;
			}


			String tmp_str[] = br.readLine().split("\\s+");
			int array[] = new int[N];

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

			int swap_count = 0,work;

			for(int i = 0; i < N-1; i++){
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			}

			StringBuilder sb = new StringBuilder();
			sb.append(Integer.toBinaryString(array[0]));
			for(int i = 1; i < array.length; i++){
				sb.append(" ").append(Integer.toString(array[i]));
			}
			System.out.println(sb.toString());
			System.out.println(swap_count);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static final int BIG_NUM  = 2000000000;
	public static final int MOD  = 1000000007;

	public static void main(String[] args) {

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

		try {
			int N = Integer.parseInt(br.readLine());
			if(N == 1){
				System.out.println(br.readLine());
				System.out.println(0);
				return;
			}


			String tmp_str[] = br.readLine().split("\\s+");
			int array[] = new int[N];

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

			int swap_count = 0,work;

			for(int i = 0; i < N-1; i++){
				for(int k = N-1; k >= i+1; k--){
					if(array[k] < array[k-1]){
						work = array[k-1];
						array[k-1] = array[k];
						array[k] = work;
						swap_count++;
					}
				}
			}

			StringBuilder sb = new StringBuilder();
			sb.append(Integer.toBinaryString(array[0]));
			for(int i = 1; i < array.length; i++){
				sb.append(" ").append(Integer.toString(array[i]));
			}
			System.out.println(sb.toString());
			System.out.println(swap_count);

		} catch (NumberFormatException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

