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

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		byte arrayLength = Byte.parseByte(in.readLine());
		byte[] array = new byte[arrayLength];
		short count = 0;
		String[] strData = in.readLine().split(" ");
		for (byte i = 0; i < arrayLength; i++) {
			array[i] = Byte.parseByte(strData[i]);
		}
		for (int x = 0; x < arrayLength; x++) {
			for (byte y = (byte) (arrayLength - 1); y > x; y--) {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			}
		}
		for (int z = 0; z < arrayLength; z++) {
			if (z == arrayLength - 1) {
				System.out.println(array[z]);
			} else {
				System.out.print(array[z] + " ");
			}
		}
		System.out.println(count);
	}
} 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 NumberFormatException,
			IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		byte arrayLength = Byte.parseByte(in.readLine());
		byte[] array = new byte[arrayLength];
		short count = 0;
		String[] strData = in.readLine().split(" ");
		for (byte i = 0; i < arrayLength; i++) {
			array[i] = Byte.parseByte(strData[i]);
		}
		for (int x = 0; x < arrayLength; x++) {
			for (byte y = (byte) (arrayLength - 1); y > x; y--) {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			}
		}
		for (int z = 0; z < arrayLength; z++) {
			if (z == arrayLength - 1) {
				System.out.println(array[z]);
			} else {
				System.out.print(array[z] + " ");
			}
		}
		System.out.println(count);
	}
} Main public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		byte arrayLength = Byte.parseByte(in.readLine());
		byte[] array = new byte[arrayLength];
		short count = 0;
		String[] strData = in.readLine().split(" ");
		for (byte i = 0; i < arrayLength; i++) {
			array[i] = Byte.parseByte(strData[i]);
		}
		for (int x = 0; x < arrayLength; x++) {
			for (byte y = (byte) (arrayLength - 1); y > x; y--) {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			}
		}
		for (int z = 0; z < arrayLength; z++) {
			if (z == arrayLength - 1) {
				System.out.println(array[z]);
			} else {
				System.out.print(array[z] + " ");
			}
		}
		System.out.println(count);
	} main {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		byte arrayLength = Byte.parseByte(in.readLine());
		byte[] array = new byte[arrayLength];
		short count = 0;
		String[] strData = in.readLine().split(" ");
		for (byte i = 0; i < arrayLength; i++) {
			array[i] = Byte.parseByte(strData[i]);
		}
		for (int x = 0; x < arrayLength; x++) {
			for (byte y = (byte) (arrayLength - 1); y > x; y--) {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			}
		}
		for (int z = 0; z < arrayLength; z++) {
			if (z == arrayLength - 1) {
				System.out.println(array[z]);
			} else {
				System.out.print(array[z] + " ");
			}
		}
		System.out.println(count);
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) byte arrayLength = Byte.parseByte(in.readLine()); arrayLength Byte.parseByte(in.readLine()) Byte.parseByte Byte in.readLine() in.readLine in byte[] array = new byte[arrayLength]; array new byte[arrayLength] arrayLength short count = 0; count 0 String[] strData = in.readLine().split(" "); strData in.readLine().split(" ") in.readLine().split in.readLine() in.readLine in " " for (byte i = 0; i < arrayLength; i++) {
			array[i] = Byte.parseByte(strData[i]);
		} byte i = 0; byte i = 0; i 0 i < arrayLength i arrayLength i++ i++ i {
			array[i] = Byte.parseByte(strData[i]);
		} {
			array[i] = Byte.parseByte(strData[i]);
		} array[i] = Byte.parseByte(strData[i]) array[i] array i Byte.parseByte(strData[i]) Byte.parseByte Byte strData[i] strData i for (int x = 0; x < arrayLength; x++) {
			for (byte y = (byte) (arrayLength - 1); y > x; y--) {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			}
		} int x = 0; int x = 0; x 0 x < arrayLength x arrayLength x++ x++ x {
			for (byte y = (byte) (arrayLength - 1); y > x; y--) {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			}
		} {
			for (byte y = (byte) (arrayLength - 1); y > x; y--) {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			}
		} for (byte y = (byte) (arrayLength - 1); y > x; y--) {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			} byte y = (byte) (arrayLength - 1); byte y = (byte) (arrayLength - 1); y (byte) (arrayLength - 1) arrayLength 1 y > x y x y-- y-- y {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			} {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			} if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				} array[y] < array[y - 1] array[y] array y array[y - 1] array y - 1 y 1 {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				} byte temp = array[y]; temp array[y] array y array[y] = array[y - 1] array[y] array y array[y - 1] array y - 1 y 1 array[y - 1] = temp array[y - 1] array y - 1 y 1 temp count++ count for (int z = 0; z < arrayLength; z++) {
			if (z == arrayLength - 1) {
				System.out.println(array[z]);
			} else {
				System.out.print(array[z] + " ");
			}
		} int z = 0; int z = 0; z 0 z < arrayLength z arrayLength z++ z++ z {
			if (z == arrayLength - 1) {
				System.out.println(array[z]);
			} else {
				System.out.print(array[z] + " ");
			}
		} {
			if (z == arrayLength - 1) {
				System.out.println(array[z]);
			} else {
				System.out.print(array[z] + " ");
			}
		} if (z == arrayLength - 1) {
				System.out.println(array[z]);
			} else {
				System.out.print(array[z] + " ");
			} z == arrayLength - 1 z arrayLength - 1 arrayLength 1 {
				System.out.println(array[z]);
			} System.out.println(array[z]) System.out.println System.out System System.out array[z] array z {
				System.out.print(array[z] + " ");
			} System.out.print(array[z] + " ") System.out.print System.out System System.out array[z] + " " array[z] array z " " System.out.println(count) System.out.println System.out System System.out count String[] args args public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		byte arrayLength = Byte.parseByte(in.readLine());
		byte[] array = new byte[arrayLength];
		short count = 0;
		String[] strData = in.readLine().split(" ");
		for (byte i = 0; i < arrayLength; i++) {
			array[i] = Byte.parseByte(strData[i]);
		}
		for (int x = 0; x < arrayLength; x++) {
			for (byte y = (byte) (arrayLength - 1); y > x; y--) {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			}
		}
		for (int z = 0; z < arrayLength; z++) {
			if (z == arrayLength - 1) {
				System.out.println(array[z]);
			} else {
				System.out.print(array[z] + " ");
			}
		}
		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		byte arrayLength = Byte.parseByte(in.readLine());
		byte[] array = new byte[arrayLength];
		short count = 0;
		String[] strData = in.readLine().split(" ");
		for (byte i = 0; i < arrayLength; i++) {
			array[i] = Byte.parseByte(strData[i]);
		}
		for (int x = 0; x < arrayLength; x++) {
			for (byte y = (byte) (arrayLength - 1); y > x; y--) {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			}
		}
		for (int z = 0; z < arrayLength; z++) {
			if (z == arrayLength - 1) {
				System.out.println(array[z]);
			} else {
				System.out.print(array[z] + " ");
			}
		}
		System.out.println(count);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		byte arrayLength = Byte.parseByte(in.readLine());
		byte[] array = new byte[arrayLength];
		short count = 0;
		String[] strData = in.readLine().split(" ");
		for (byte i = 0; i < arrayLength; i++) {
			array[i] = Byte.parseByte(strData[i]);
		}
		for (int x = 0; x < arrayLength; x++) {
			for (byte y = (byte) (arrayLength - 1); y > x; y--) {
				if (array[y] < array[y - 1]) {
					byte temp = array[y];
					array[y] = array[y - 1];
					array[y - 1] = temp;
					count++;
				}
			}
		}
		for (int z = 0; z < arrayLength; z++) {
			if (z == arrayLength - 1) {
				System.out.println(array[z]);
			} else {
				System.out.print(array[z] + " ");
			}
		}
		System.out.println(count);
	}
}