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());
		String[] strs = br.readLine().split(" ");
		int[] inputData = new int[n];
		for (int i = 0; i < n; i++) {
			inputData[i] = Integer.parseInt(strs[i]);
		}
		int swapCnt = bubbleSort(inputData, n);
		printArray(inputData);
		System.out.println(swapCnt);

	}

	public static int bubbleSort(int[] A, int N) {
		int swapCnt = 0;
		boolean flag = true;
		while (flag) {
			flag = false;
			for (int i = N - 1; i > 0; i--) {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			}
		}
		return swapCnt;
	}

	public static void printArray(int[] target) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < target.length; i++) {
			sb.append(target[i]);
			if (i < target.length - 1) {
				sb.append(" ");
			}
		}
		System.out.println(sb.toString());
	}
} 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());
		String[] strs = br.readLine().split(" ");
		int[] inputData = new int[n];
		for (int i = 0; i < n; i++) {
			inputData[i] = Integer.parseInt(strs[i]);
		}
		int swapCnt = bubbleSort(inputData, n);
		printArray(inputData);
		System.out.println(swapCnt);

	}

	public static int bubbleSort(int[] A, int N) {
		int swapCnt = 0;
		boolean flag = true;
		while (flag) {
			flag = false;
			for (int i = N - 1; i > 0; i--) {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			}
		}
		return swapCnt;
	}

	public static void printArray(int[] target) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < target.length; i++) {
			sb.append(target[i]);
			if (i < target.length - 1) {
				sb.append(" ");
			}
		}
		System.out.println(sb.toString());
	}
} Main public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] strs = br.readLine().split(" ");
		int[] inputData = new int[n];
		for (int i = 0; i < n; i++) {
			inputData[i] = Integer.parseInt(strs[i]);
		}
		int swapCnt = bubbleSort(inputData, n);
		printArray(inputData);
		System.out.println(swapCnt);

	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String[] strs = br.readLine().split(" ");
		int[] inputData = new int[n];
		for (int i = 0; i < n; i++) {
			inputData[i] = Integer.parseInt(strs[i]);
		}
		int swapCnt = bubbleSort(inputData, n);
		printArray(inputData);
		System.out.println(swapCnt);

	} 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 String[] strs = br.readLine().split(" "); strs br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int[] inputData = new int[n]; inputData new int[n] n for (int i = 0; i < n; i++) {
			inputData[i] = Integer.parseInt(strs[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			inputData[i] = Integer.parseInt(strs[i]);
		} {
			inputData[i] = Integer.parseInt(strs[i]);
		} inputData[i] = Integer.parseInt(strs[i]) inputData[i] inputData i Integer.parseInt(strs[i]) Integer.parseInt Integer strs[i] strs i int swapCnt = bubbleSort(inputData, n); swapCnt bubbleSort(inputData, n) bubbleSort inputData n printArray(inputData) printArray inputData System.out.println(swapCnt) System.out.println System.out System System.out swapCnt String[] args args public static int bubbleSort(int[] A, int N) {
		int swapCnt = 0;
		boolean flag = true;
		while (flag) {
			flag = false;
			for (int i = N - 1; i > 0; i--) {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			}
		}
		return swapCnt;
	} bubbleSort {
		int swapCnt = 0;
		boolean flag = true;
		while (flag) {
			flag = false;
			for (int i = N - 1; i > 0; i--) {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			}
		}
		return swapCnt;
	} int swapCnt = 0; swapCnt 0 boolean flag = true; flag true while (flag) {
			flag = false;
			for (int i = N - 1; i > 0; i--) {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			}
		} flag {
			flag = false;
			for (int i = N - 1; i > 0; i--) {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			}
		} flag = false flag false for (int i = N - 1; i > 0; i--) {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			} int i = N - 1; int i = N - 1; i N - 1 N 1 i > 0 i 0 i-- i-- i {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			} {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			} if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				} A[i] < A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				} int temp = A[i]; temp A[i] A i A[i] = A[i - 1] A[i] A i A[i - 1] A i - 1 i 1 A[i - 1] = temp A[i - 1] A i - 1 i 1 temp swapCnt++ swapCnt flag = true flag true return swapCnt; swapCnt int[] A A int N N public static void printArray(int[] target) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < target.length; i++) {
			sb.append(target[i]);
			if (i < target.length - 1) {
				sb.append(" ");
			}
		}
		System.out.println(sb.toString());
	} printArray {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < target.length; i++) {
			sb.append(target[i]);
			if (i < target.length - 1) {
				sb.append(" ");
			}
		}
		System.out.println(sb.toString());
	} StringBuilder sb = new StringBuilder(); sb new StringBuilder() for (int i = 0; i < target.length; i++) {
			sb.append(target[i]);
			if (i < target.length - 1) {
				sb.append(" ");
			}
		} int i = 0; int i = 0; i 0 i < target.length i target.length target target.length i++ i++ i {
			sb.append(target[i]);
			if (i < target.length - 1) {
				sb.append(" ");
			}
		} {
			sb.append(target[i]);
			if (i < target.length - 1) {
				sb.append(" ");
			}
		} sb.append(target[i]) sb.append sb target[i] target i if (i < target.length - 1) {
				sb.append(" ");
			} i < target.length - 1 i target.length - 1 target.length target target.length 1 {
				sb.append(" ");
			} sb.append(" ") sb.append sb " " System.out.println(sb.toString()) System.out.println System.out System System.out sb.toString() sb.toString sb int[] target target 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());
		String[] strs = br.readLine().split(" ");
		int[] inputData = new int[n];
		for (int i = 0; i < n; i++) {
			inputData[i] = Integer.parseInt(strs[i]);
		}
		int swapCnt = bubbleSort(inputData, n);
		printArray(inputData);
		System.out.println(swapCnt);

	}

	public static int bubbleSort(int[] A, int N) {
		int swapCnt = 0;
		boolean flag = true;
		while (flag) {
			flag = false;
			for (int i = N - 1; i > 0; i--) {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			}
		}
		return swapCnt;
	}

	public static void printArray(int[] target) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < target.length; i++) {
			sb.append(target[i]);
			if (i < target.length - 1) {
				sb.append(" ");
			}
		}
		System.out.println(sb.toString());
	}
} 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());
		String[] strs = br.readLine().split(" ");
		int[] inputData = new int[n];
		for (int i = 0; i < n; i++) {
			inputData[i] = Integer.parseInt(strs[i]);
		}
		int swapCnt = bubbleSort(inputData, n);
		printArray(inputData);
		System.out.println(swapCnt);

	}

	public static int bubbleSort(int[] A, int N) {
		int swapCnt = 0;
		boolean flag = true;
		while (flag) {
			flag = false;
			for (int i = N - 1; i > 0; i--) {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			}
		}
		return swapCnt;
	}

	public static void printArray(int[] target) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < target.length; i++) {
			sb.append(target[i]);
			if (i < target.length - 1) {
				sb.append(" ");
			}
		}
		System.out.println(sb.toString());
	}
} 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());
		String[] strs = br.readLine().split(" ");
		int[] inputData = new int[n];
		for (int i = 0; i < n; i++) {
			inputData[i] = Integer.parseInt(strs[i]);
		}
		int swapCnt = bubbleSort(inputData, n);
		printArray(inputData);
		System.out.println(swapCnt);

	}

	public static int bubbleSort(int[] A, int N) {
		int swapCnt = 0;
		boolean flag = true;
		while (flag) {
			flag = false;
			for (int i = N - 1; i > 0; i--) {
				if (A[i] < A[i - 1] ) {
					int temp = A[i];
					A[i] = A[i - 1];
					A[i - 1] = temp;
					swapCnt++;
					flag = true;
				}
			}
		}
		return swapCnt;
	}

	public static void printArray(int[] target) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < target.length; i++) {
			sb.append(target[i]);
			if (i < target.length - 1) {
				sb.append(" ");
			}
		}
		System.out.println(sb.toString());
	}
}