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) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			int[] array = new int[n];
			String input = br.readLine();
			String[] s = input.split("\\s");
			for (int i = 0; i < array.length; i++) {
				array[i] = Integer.parseInt(s[i]);
			}
			System.out.println(bubbleSort(array));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	// バブルソート
	public static int bubbleSort(int[] array) {
		int cnt = 0;// 交換回数
		boolean flg = true;
		for (int i = 0; flg; i++) { // iは未ソート部分列の先頭インデックス
			flg = false;
			for (int j = array.length - 1; j > i; j--) {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			}

		}
		// 表示
		String str = Arrays.toString(array);
		System.out.println(str.replace("[", "").replace("]", "").replace(",", ""));
		return cnt;
	}

} 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) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			int[] array = new int[n];
			String input = br.readLine();
			String[] s = input.split("\\s");
			for (int i = 0; i < array.length; i++) {
				array[i] = Integer.parseInt(s[i]);
			}
			System.out.println(bubbleSort(array));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	// バブルソート
	public static int bubbleSort(int[] array) {
		int cnt = 0;// 交換回数
		boolean flg = true;
		for (int i = 0; flg; i++) { // iは未ソート部分列の先頭インデックス
			flg = false;
			for (int j = array.length - 1; j > i; j--) {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			}

		}
		// 表示
		String str = Arrays.toString(array);
		System.out.println(str.replace("[", "").replace("]", "").replace(",", ""));
		return cnt;
	}

} Main public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			int[] array = new int[n];
			String input = br.readLine();
			String[] s = input.split("\\s");
			for (int i = 0; i < array.length; i++) {
				array[i] = Integer.parseInt(s[i]);
			}
			System.out.println(bubbleSort(array));
		} catch (IOException e) {
			e.printStackTrace();
		}

	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			int[] array = new int[n];
			String input = br.readLine();
			String[] s = input.split("\\s");
			for (int i = 0; i < array.length; i++) {
				array[i] = Integer.parseInt(s[i]);
			}
			System.out.println(bubbleSort(array));
		} catch (IOException e) {
			e.printStackTrace();
		}

	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try {
			int n = Integer.parseInt(br.readLine());
			int[] array = new int[n];
			String input = br.readLine();
			String[] s = input.split("\\s");
			for (int i = 0; i < array.length; i++) {
				array[i] = Integer.parseInt(s[i]);
			}
			System.out.println(bubbleSort(array));
		} catch (IOException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} IOException e {
			e.printStackTrace();
		} e.printStackTrace() e.printStackTrace e {
			int n = Integer.parseInt(br.readLine());
			int[] array = new int[n];
			String input = br.readLine();
			String[] s = input.split("\\s");
			for (int i = 0; i < array.length; i++) {
				array[i] = Integer.parseInt(s[i]);
			}
			System.out.println(bubbleSort(array));
		} int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] array = new int[n]; array new int[n] n String input = br.readLine(); input br.readLine() br.readLine br String[] s = input.split("\\s"); s input.split("\\s") input.split input "\\s" for (int i = 0; i < array.length; i++) {
				array[i] = Integer.parseInt(s[i]);
			} int i = 0; int i = 0; i 0 i < array.length i array.length array array.length i++ i++ i {
				array[i] = Integer.parseInt(s[i]);
			} {
				array[i] = Integer.parseInt(s[i]);
			} array[i] = Integer.parseInt(s[i]) array[i] array i Integer.parseInt(s[i]) Integer.parseInt Integer s[i] s i System.out.println(bubbleSort(array)) System.out.println System.out System System.out bubbleSort(array) bubbleSort array String[] args args // バブルソート
	public static int bubbleSort(int[] array) {
		int cnt = 0;// 交換回数
		boolean flg = true;
		for (int i = 0; flg; i++) { // iは未ソート部分列の先頭インデックス
			flg = false;
			for (int j = array.length - 1; j > i; j--) {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			}

		}
		// 表示
		String str = Arrays.toString(array);
		System.out.println(str.replace("[", "").replace("]", "").replace(",", ""));
		return cnt;
	} bubbleSort {
		int cnt = 0;// 交換回数
		boolean flg = true;
		for (int i = 0; flg; i++) { // iは未ソート部分列の先頭インデックス
			flg = false;
			for (int j = array.length - 1; j > i; j--) {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			}

		}
		// 表示
		String str = Arrays.toString(array);
		System.out.println(str.replace("[", "").replace("]", "").replace(",", ""));
		return cnt;
	} int cnt = 0; cnt 0 boolean flg = true; flg true for (int i = 0; flg; i++) { // iは未ソート部分列の先頭インデックス
			flg = false;
			for (int j = array.length - 1; j > i; j--) {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			}

		} int i = 0; int i = 0; i 0 flg i++ i++ i { // iは未ソート部分列の先頭インデックス
			flg = false;
			for (int j = array.length - 1; j > i; j--) {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			}

		} { // iは未ソート部分列の先頭インデックス
			flg = false;
			for (int j = array.length - 1; j > i; j--) {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			}

		} flg = false flg false for (int j = array.length - 1; j > i; j--) {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			} int j = array.length - 1; int j = array.length - 1; j array.length - 1 array.length array array.length 1 j > i j i j-- j-- j {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			} {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			} if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				} array[j] < array[j - 1] array[j] array j array[j - 1] array j - 1 j 1 {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				} int tmp = array[j - 1]; tmp array[j - 1] array j - 1 j 1 array[j - 1] = array[j] array[j - 1] array j - 1 j 1 array[j] array j array[j] = tmp array[j] array j tmp flg = true flg true cnt++ cnt String str = Arrays.toString(array); str Arrays.toString(array) Arrays.toString Arrays array System.out.println(str.replace("[", "").replace("]", "").replace(",", "")) System.out.println System.out System System.out str.replace("[", "").replace("]", "").replace(",", "") str.replace("[", "").replace("]", "").replace str.replace("[", "").replace("]", "") str.replace("[", "").replace str.replace("[", "") str.replace str "[" "" "]" "" "," "" return cnt; cnt int[] array array public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			int[] array = new int[n];
			String input = br.readLine();
			String[] s = input.split("\\s");
			for (int i = 0; i < array.length; i++) {
				array[i] = Integer.parseInt(s[i]);
			}
			System.out.println(bubbleSort(array));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	// バブルソート
	public static int bubbleSort(int[] array) {
		int cnt = 0;// 交換回数
		boolean flg = true;
		for (int i = 0; flg; i++) { // iは未ソート部分列の先頭インデックス
			flg = false;
			for (int j = array.length - 1; j > i; j--) {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			}

		}
		// 表示
		String str = Arrays.toString(array);
		System.out.println(str.replace("[", "").replace("]", "").replace(",", ""));
		return cnt;
	}

} public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			int[] array = new int[n];
			String input = br.readLine();
			String[] s = input.split("\\s");
			for (int i = 0; i < array.length; i++) {
				array[i] = Integer.parseInt(s[i]);
			}
			System.out.println(bubbleSort(array));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	// バブルソート
	public static int bubbleSort(int[] array) {
		int cnt = 0;// 交換回数
		boolean flg = true;
		for (int i = 0; flg; i++) { // iは未ソート部分列の先頭インデックス
			flg = false;
			for (int j = array.length - 1; j > i; j--) {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			}

		}
		// 表示
		String str = Arrays.toString(array);
		System.out.println(str.replace("[", "").replace("]", "").replace(",", ""));
		return cnt;
	}

} 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) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try {
			int n = Integer.parseInt(br.readLine());
			int[] array = new int[n];
			String input = br.readLine();
			String[] s = input.split("\\s");
			for (int i = 0; i < array.length; i++) {
				array[i] = Integer.parseInt(s[i]);
			}
			System.out.println(bubbleSort(array));
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	// バブルソート
	public static int bubbleSort(int[] array) {
		int cnt = 0;// 交換回数
		boolean flg = true;
		for (int i = 0; flg; i++) { // iは未ソート部分列の先頭インデックス
			flg = false;
			for (int j = array.length - 1; j > i; j--) {
				if (array[j] < array[j - 1]) {
					int tmp = array[j - 1];
					array[j - 1] = array[j];
					array[j] = tmp;
					flg = true;
					cnt++;
				}
			}

		}
		// 表示
		String str = Arrays.toString(array);
		System.out.println(str.replace("[", "").replace("]", "").replace(",", ""));
		return cnt;
	}

}
