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

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int count = Integer.parseInt(br.readLine());

		String[] str = br.readLine().split(" ");
		int[] numList = new int[count];
		for (int i = 0; i < count; i++) {
			numList[i] = Integer.parseInt(str[i]);
		}
		Tool.bubleSort(numList, count);
	}
}

class Tool {
	static void bubleSort(int[] numList, int count) {
		StringBuffer sb = new StringBuffer();
		int flag = 0;
		for (int i = 0; i < count; i++) {
			for (int j = count - 1; j > i; j--) {
				if (numList[j - 1] > numList[j]) {
					int temp = numList[j];
					numList[j] = numList[j - 1];
					numList[j - 1] = temp;
					flag++;
					j = count;
				}
			}
		}
		sb.append(numList[0]);
		for(int i = 1; i < count; i++){
			sb.append(" " + numList[i]);
		}
		System.out.println(sb.toString() + "\n" + flag);
	}
}
/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