import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.StringBuilder;

/*Question
/??????????????????????????????????????¨?????????????????????Bubble???????°´??¢???????????£???????????????????????????????´??????????????????????????????????????????????????¬???????????????¢?????´???????????§??°????????????????????????????????????
/1 bubbleSort(A, N) // N ??????????´?????????? 0-????????????????????? A
/2 flag = 1 // ????????£??\????´?????????¨??????
/3 while flag
/4 flag = 0
/5 for j ??? N-1 ?????? 1 ?????§
/6 if A[j] < A[j-1]
/7 A[j] ??¨ A[j-1] ?????????
/8 flag = 1
/??°??? A ??????????????????????????????????????§?????????????????????????????????????????°?????????????????????????????????????????????????????????????????§????????????????´???????????????°?????±???????????????????????? 
*/

/*Input
/??\??????????????????????????°?????????????????¨?????´??° N ???????????????????????????????????????N ????????´??°????????????????????§?????????????????????
*/

public class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader sc = new BufferedReader(new InputStreamReader(System.in));
		//???????????°????¢??????¨
		int k;
		/*??\???
		/??????????´???°?????\???????¬??????°????????\???
		*/
		int n = Integer.parseInt(sc.readLine());
		int[] a = new int[n];
		String[] st = sc.readLine().split(" ");
		for(int i = 0;i < n;i++){
			a[i] = Integer.parseInt(st[i]);
		}
		/*??°??????Bubble???????????????
		/????????????????????§?????????????????????
		/??????????????£??????????????§??????
		*/
		k = Bubble(a);
		System.out.println(k);
	}

	/*Bubble????????????
	/???????????????????????????
	@return int
	*/

	public static int Bubble(int[] a) {
		//????????¨
		StringBuilder br = new StringBuilder();
		//?????°???????????????
		int s = 0;
		//????????????????????????????????\????????¨
		int t;
		for (int i = 0;i < a.length-1;i++) {
			for (int j = a.length-1;j > i;j--) {
				if (a[j] < a[j-1]){
					t = a[j];
					a[j] = a[j-1];
					a[j-1] = t;
					s++;
				}
			}
		}
		//??????
		for (int n:a)
			br.append(n+" ");
		br.deleteCharAt(br.lastIndexOf(" "));
		System.out.println(br);
		return s;
	}
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz