import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  num = scanner.nextInt();//要素数
		int array[] = new int[num];
		int count = 0;
		
		for(int i = 0; i < num; i ++ ){
			array[i] = scanner.nextInt();
		}
		
		count = bubbleSort(array, num);

		System.out.println(count);
		
		scanner.close();
	}

	public static int bubbleSort( int[] numArray, int num){ // N 個の要素を含む 0-オリジンの配列 A
		int count = 0;
		
		//バブルソート処理
		for (int i = 0; i < num - 1; i++) {
				for (int j = num - 1; j > i; j--) {
					if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					}
				}
			}
		//出力
		for(int i = 0; i < num; i ++ ){
			System.out.print(numArray[i]);
			if( i == num - 1) {
			System.out.print("\n");
			}else {
				System.out.print(" ");
			}
		}
		return count;
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  num = scanner.nextInt();//要素数
		int array[] = new int[num];
		int count = 0;
		
		for(int i = 0; i < num; i ++ ){
			array[i] = scanner.nextInt();
		}
		
		count = bubbleSort(array, num);

		System.out.println(count);
		
		scanner.close();
	}

	public static int bubbleSort( int[] numArray, int num){ // N 個の要素を含む 0-オリジンの配列 A
		int count = 0;
		
		//バブルソート処理
		for (int i = 0; i < num - 1; i++) {
				for (int j = num - 1; j > i; j--) {
					if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					}
				}
			}
		//出力
		for(int i = 0; i < num; i ++ ){
			System.out.print(numArray[i]);
			if( i == num - 1) {
			System.out.print("\n");
			}else {
				System.out.print(" ");
			}
		}
		return count;
	}
} Main public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  num = scanner.nextInt();//要素数
		int array[] = new int[num];
		int count = 0;
		
		for(int i = 0; i < num; i ++ ){
			array[i] = scanner.nextInt();
		}
		
		count = bubbleSort(array, num);

		System.out.println(count);
		
		scanner.close();
	} main {
		Scanner scanner = new Scanner(System.in);
		int  num = scanner.nextInt();//要素数
		int array[] = new int[num];
		int count = 0;
		
		for(int i = 0; i < num; i ++ ){
			array[i] = scanner.nextInt();
		}
		
		count = bubbleSort(array, num);

		System.out.println(count);
		
		scanner.close();
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int  num = scanner.nextInt(); num scanner.nextInt() scanner.nextInt scanner int array[] = new int[num]; array new int[num] num int count = 0; count 0 for(int i = 0; i < num; i ++ ){
			array[i] = scanner.nextInt();
		} int i = 0; int i = 0; i 0 i < num i num i ++ i ++ i {
			array[i] = scanner.nextInt();
		} {
			array[i] = scanner.nextInt();
		} array[i] = scanner.nextInt() array[i] array i scanner.nextInt() scanner.nextInt scanner count = bubbleSort(array, num) count bubbleSort(array, num) bubbleSort array num System.out.println(count) System.out.println System.out System System.out count scanner.close() scanner.close scanner String args[] args public static int bubbleSort( int[] numArray, int num){ // N 個の要素を含む 0-オリジンの配列 A
		int count = 0;
		
		//バブルソート処理
		for (int i = 0; i < num - 1; i++) {
				for (int j = num - 1; j > i; j--) {
					if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					}
				}
			}
		//出力
		for(int i = 0; i < num; i ++ ){
			System.out.print(numArray[i]);
			if( i == num - 1) {
			System.out.print("\n");
			}else {
				System.out.print(" ");
			}
		}
		return count;
	} bubbleSort { // N 個の要素を含む 0-オリジンの配列 A
		int count = 0;
		
		//バブルソート処理
		for (int i = 0; i < num - 1; i++) {
				for (int j = num - 1; j > i; j--) {
					if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					}
				}
			}
		//出力
		for(int i = 0; i < num; i ++ ){
			System.out.print(numArray[i]);
			if( i == num - 1) {
			System.out.print("\n");
			}else {
				System.out.print(" ");
			}
		}
		return count;
	} int count = 0; count 0 for (int i = 0; i < num - 1; i++) {
				for (int j = num - 1; j > i; j--) {
					if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					}
				}
			} int i = 0; int i = 0; i 0 i < num - 1 i num - 1 num 1 i++ i++ i {
				for (int j = num - 1; j > i; j--) {
					if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					}
				}
			} {
				for (int j = num - 1; j > i; j--) {
					if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					}
				}
			} for (int j = num - 1; j > i; j--) {
					if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					}
				} int j = num - 1; int j = num - 1; j num - 1 num 1 j > i j i j-- j-- j {
					if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					}
				} {
					if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					}
				} if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					} numArray[j - 1] > numArray[j] numArray[j - 1] numArray j - 1 j 1 numArray[j] numArray j {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					} int work = numArray[j - 1]; work 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] = work numArray[j] numArray j work count++ count for(int i = 0; i < num; i ++ ){
			System.out.print(numArray[i]);
			if( i == num - 1) {
			System.out.print("\n");
			}else {
				System.out.print(" ");
			}
		} int i = 0; int i = 0; i 0 i < num i num i ++ i ++ i {
			System.out.print(numArray[i]);
			if( i == num - 1) {
			System.out.print("\n");
			}else {
				System.out.print(" ");
			}
		} {
			System.out.print(numArray[i]);
			if( i == num - 1) {
			System.out.print("\n");
			}else {
				System.out.print(" ");
			}
		} System.out.print(numArray[i]) System.out.print System.out System System.out numArray[i] numArray i if( i == num - 1) {
			System.out.print("\n");
			}else {
				System.out.print(" ");
			} i == num - 1 i num - 1 num 1 {
			System.out.print("\n");
			} System.out.print("\n") System.out.print System.out System System.out "\n" {
				System.out.print(" ");
			} System.out.print(" ") System.out.print System.out System System.out " " return count; count int[] numArray numArray int num num
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scanner = new Scanner(System.in);
		int  num = scanner.nextInt();//要素数
		int array[] = new int[num];
		int count = 0;
		
		for(int i = 0; i < num; i ++ ){
			array[i] = scanner.nextInt();
		}
		
		count = bubbleSort(array, num);

		System.out.println(count);
		
		scanner.close();
	}

	public static int bubbleSort( int[] numArray, int num){ // N 個の要素を含む 0-オリジンの配列 A
		int count = 0;
		
		//バブルソート処理
		for (int i = 0; i < num - 1; i++) {
				for (int j = num - 1; j > i; j--) {
					if (numArray[j - 1] > numArray[j]) {
						int work = numArray[j - 1];
						numArray[j - 1] = numArray[j];
						numArray[j] = work;
						count++;
					}
				}
			}
		//出力
		for(int i = 0; i < num; i ++ ){
			System.out.print(numArray[i]);
			if( i == num - 1) {
			System.out.print("\n");
			}else {
				System.out.print(" ");
			}
		}
		return count;
	}
}
