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

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int elementNum = Integer.parseInt(br.readLine());
		String line = br.readLine();
		int[] numArray = parseInt(getSplitLine(line));

		int count = 0;
		for (int i = 0; i < numArray.length - 1; i++) {
			for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			}
		}
		System.out.println(Arrays.toString(numArray)
				.replaceAll("[\\[\\],]", ""));
		System.out.println(count);
	}

	private static String[] getSplitLine(String line) {
		return line.split("\\s");
	}

	private static int[] parseInt(String[] line) {
		int[] numArray = new int[line.length];
		for (int i = 0; i < line.length; i++) {
			numArray[i] = Integer.parseInt(line[i]);
		}
		return numArray;
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.Arrays; Arrays java.util public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int elementNum = Integer.parseInt(br.readLine());
		String line = br.readLine();
		int[] numArray = parseInt(getSplitLine(line));

		int count = 0;
		for (int i = 0; i < numArray.length - 1; i++) {
			for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			}
		}
		System.out.println(Arrays.toString(numArray)
				.replaceAll("[\\[\\],]", ""));
		System.out.println(count);
	}

	private static String[] getSplitLine(String line) {
		return line.split("\\s");
	}

	private static int[] parseInt(String[] line) {
		int[] numArray = new int[line.length];
		for (int i = 0; i < line.length; i++) {
			numArray[i] = Integer.parseInt(line[i]);
		}
		return numArray;
	}

} Main public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int elementNum = Integer.parseInt(br.readLine());
		String line = br.readLine();
		int[] numArray = parseInt(getSplitLine(line));

		int count = 0;
		for (int i = 0; i < numArray.length - 1; i++) {
			for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			}
		}
		System.out.println(Arrays.toString(numArray)
				.replaceAll("[\\[\\],]", ""));
		System.out.println(count);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int elementNum = Integer.parseInt(br.readLine());
		String line = br.readLine();
		int[] numArray = parseInt(getSplitLine(line));

		int count = 0;
		for (int i = 0; i < numArray.length - 1; i++) {
			for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			}
		}
		System.out.println(Arrays.toString(numArray)
				.replaceAll("[\\[\\],]", ""));
		System.out.println(count);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int elementNum = Integer.parseInt(br.readLine()); elementNum Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br String line = br.readLine(); line br.readLine() br.readLine br int[] numArray = parseInt(getSplitLine(line)); numArray parseInt(getSplitLine(line)) parseInt getSplitLine(line) getSplitLine line int count = 0; count 0 for (int i = 0; i < numArray.length - 1; i++) {
			for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			}
		} int i = 0; int i = 0; i 0 i < numArray.length - 1 i numArray.length - 1 numArray.length numArray numArray.length 1 i++ i++ i {
			for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			}
		} {
			for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			}
		} for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			} int j = numArray.length - 1; int j = numArray.length - 1; j numArray.length - 1 numArray.length numArray numArray.length 1 j > i j i j-- j-- j {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			} {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			} if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				} numArray[j - 1] > numArray[j] numArray[j - 1] numArray j - 1 j 1 numArray[j] numArray j {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				} int tmpNum = numArray[j - 1]; tmpNum numArray[j - 1] numArray j - 1 j 1 numArray[j - 1] = numArray[j] numArray[j - 1] numArray j - 1 j 1 numArray[j] numArray j numArray[j] = tmpNum numArray[j] numArray j tmpNum count++ count System.out.println(Arrays.toString(numArray)
				.replaceAll("[\\[\\],]", "")) System.out.println System.out System System.out Arrays.toString(numArray)
				.replaceAll("[\\[\\],]", "") Arrays.toString(numArray)
				.replaceAll Arrays.toString(numArray) Arrays.toString Arrays numArray "[\\[\\],]" "" System.out.println(count) System.out.println System.out System System.out count String args[] args private static String[] getSplitLine(String line) {
		return line.split("\\s");
	} getSplitLine {
		return line.split("\\s");
	} return line.split("\\s"); line.split("\\s") line.split line "\\s" String line line private static int[] parseInt(String[] line) {
		int[] numArray = new int[line.length];
		for (int i = 0; i < line.length; i++) {
			numArray[i] = Integer.parseInt(line[i]);
		}
		return numArray;
	} parseInt {
		int[] numArray = new int[line.length];
		for (int i = 0; i < line.length; i++) {
			numArray[i] = Integer.parseInt(line[i]);
		}
		return numArray;
	} int[] numArray = new int[line.length]; numArray new int[line.length] line.length line line.length for (int i = 0; i < line.length; i++) {
			numArray[i] = Integer.parseInt(line[i]);
		} int i = 0; int i = 0; i 0 i < line.length i line.length line line.length i++ i++ i {
			numArray[i] = Integer.parseInt(line[i]);
		} {
			numArray[i] = Integer.parseInt(line[i]);
		} numArray[i] = Integer.parseInt(line[i]) numArray[i] numArray i Integer.parseInt(line[i]) Integer.parseInt Integer line[i] line i return numArray; numArray String[] line line public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int elementNum = Integer.parseInt(br.readLine());
		String line = br.readLine();
		int[] numArray = parseInt(getSplitLine(line));

		int count = 0;
		for (int i = 0; i < numArray.length - 1; i++) {
			for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			}
		}
		System.out.println(Arrays.toString(numArray)
				.replaceAll("[\\[\\],]", ""));
		System.out.println(count);
	}

	private static String[] getSplitLine(String line) {
		return line.split("\\s");
	}

	private static int[] parseInt(String[] line) {
		int[] numArray = new int[line.length];
		for (int i = 0; i < line.length; i++) {
			numArray[i] = Integer.parseInt(line[i]);
		}
		return numArray;
	}

} public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int elementNum = Integer.parseInt(br.readLine());
		String line = br.readLine();
		int[] numArray = parseInt(getSplitLine(line));

		int count = 0;
		for (int i = 0; i < numArray.length - 1; i++) {
			for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			}
		}
		System.out.println(Arrays.toString(numArray)
				.replaceAll("[\\[\\],]", ""));
		System.out.println(count);
	}

	private static String[] getSplitLine(String line) {
		return line.split("\\s");
	}

	private static int[] parseInt(String[] line) {
		int[] numArray = new int[line.length];
		for (int i = 0; i < line.length; i++) {
			numArray[i] = Integer.parseInt(line[i]);
		}
		return numArray;
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int elementNum = Integer.parseInt(br.readLine());
		String line = br.readLine();
		int[] numArray = parseInt(getSplitLine(line));

		int count = 0;
		for (int i = 0; i < numArray.length - 1; i++) {
			for (int j = numArray.length - 1; j > i; j--) {
				if (numArray[j - 1] > numArray[j]) {
					int tmpNum = numArray[j - 1];
					numArray[j - 1] = numArray[j];
					numArray[j] = tmpNum;
					count++;
				}
			}
		}
		System.out.println(Arrays.toString(numArray)
				.replaceAll("[\\[\\],]", ""));
		System.out.println(count);
	}

	private static String[] getSplitLine(String line) {
		return line.split("\\s");
	}

	private static int[] parseInt(String[] line) {
		int[] numArray = new int[line.length];
		for (int i = 0; i < line.length; i++) {
			numArray[i] = Integer.parseInt(line[i]);
		}
		return numArray;
	}

}