import java.util.Scanner;

public class Main {

	// define variables & initialize
	private static int cnt = 0;	// how many bubbleSort is used
	
	// sort method :: sort given array using insertion Sort
	public static void sort(int[] _A, int _n) {
		int flg = 1;
		while (flg != 0) {
			flg = 0;
			for (int i = _n - 1; i >= 1; --i) {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			}
		}
		
	}
	
	// print method :: print array
	public static void print(int[] _A) {
		for (int i = 0; i < _A.length; ++i) {
			System.out.print(_A[i]);
			if (i != _A.length - 1)
				System.out.print(" ");
		}
		System.out.println();
	}
	
	// get method :: get cnt (how many bubbleSort was used)
	public static int get() {
		return cnt;
	}
public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		////////////////////////////////////
		int n = 0;
		int[] A;
		
		n = sc.nextInt();
		A = new int[n];
		
		for (int i = 0; i < n; ++i) {
			A[i] = sc.nextInt();
		}
		
		sort(A, n);
		print(A);
		System.out.println(get());
		
		////////////////////////////////////
		sc.close();
	}



} import java.util.Scanner; Scanner java.util public class Main {

	// define variables & initialize
	private static int cnt = 0;	// how many bubbleSort is used
	
	// sort method :: sort given array using insertion Sort
	public static void sort(int[] _A, int _n) {
		int flg = 1;
		while (flg != 0) {
			flg = 0;
			for (int i = _n - 1; i >= 1; --i) {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			}
		}
		
	}
	
	// print method :: print array
	public static void print(int[] _A) {
		for (int i = 0; i < _A.length; ++i) {
			System.out.print(_A[i]);
			if (i != _A.length - 1)
				System.out.print(" ");
		}
		System.out.println();
	}
	
	// get method :: get cnt (how many bubbleSort was used)
	public static int get() {
		return cnt;
	}
public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		////////////////////////////////////
		int n = 0;
		int[] A;
		
		n = sc.nextInt();
		A = new int[n];
		
		for (int i = 0; i < n; ++i) {
			A[i] = sc.nextInt();
		}
		
		sort(A, n);
		print(A);
		System.out.println(get());
		
		////////////////////////////////////
		sc.close();
	}



} Main // define variables & initialize
	private static int cnt = 0;	// how many bubbleSort is used cnt 0 // sort method :: sort given array using insertion Sort
	public static void sort(int[] _A, int _n) {
		int flg = 1;
		while (flg != 0) {
			flg = 0;
			for (int i = _n - 1; i >= 1; --i) {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			}
		}
		
	} sort {
		int flg = 1;
		while (flg != 0) {
			flg = 0;
			for (int i = _n - 1; i >= 1; --i) {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			}
		}
		
	} int flg = 1; flg 1 while (flg != 0) {
			flg = 0;
			for (int i = _n - 1; i >= 1; --i) {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			}
		} flg != 0 flg 0 {
			flg = 0;
			for (int i = _n - 1; i >= 1; --i) {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			}
		} flg = 0 flg 0 for (int i = _n - 1; i >= 1; --i) {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			} int i = _n - 1; int i = _n - 1; i _n - 1 _n 1 i >= 1 i 1 --i --i i {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			} {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			} if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				} _A[i] < _A[i - 1] _A[i] _A i _A[i - 1] _A i - 1 i 1 {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				} _A[i] = _A[i] ^ _A[i - 1] _A[i] _A i _A[i] ^ _A[i - 1] _A[i] _A i _A[i - 1] _A i - 1 i 1 _A[i - 1] = _A[i] ^ _A[i - 1] _A[i - 1] _A i - 1 i 1 _A[i] ^ _A[i - 1] _A[i] _A i _A[i - 1] _A i - 1 i 1 _A[i] = _A[i] ^ _A[i - 1] _A[i] _A i _A[i] ^ _A[i - 1] _A[i] _A i _A[i - 1] _A i - 1 i 1 flg = 1 flg 1 ++cnt cnt int[] _A _A int _n _n // print method :: print array
	public static void print(int[] _A) {
		for (int i = 0; i < _A.length; ++i) {
			System.out.print(_A[i]);
			if (i != _A.length - 1)
				System.out.print(" ");
		}
		System.out.println();
	} print {
		for (int i = 0; i < _A.length; ++i) {
			System.out.print(_A[i]);
			if (i != _A.length - 1)
				System.out.print(" ");
		}
		System.out.println();
	} for (int i = 0; i < _A.length; ++i) {
			System.out.print(_A[i]);
			if (i != _A.length - 1)
				System.out.print(" ");
		} int i = 0; int i = 0; i 0 i < _A.length i _A.length _A _A.length ++i ++i i {
			System.out.print(_A[i]);
			if (i != _A.length - 1)
				System.out.print(" ");
		} {
			System.out.print(_A[i]);
			if (i != _A.length - 1)
				System.out.print(" ");
		} System.out.print(_A[i]) System.out.print System.out System System.out _A[i] _A i if (i != _A.length - 1)
				System.out.print(" "); i != _A.length - 1 i _A.length - 1 _A.length _A _A.length 1 System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out int[] _A _A // get method :: get cnt (how many bubbleSort was used)
	public static int get() {
		return cnt;
	} get {
		return cnt;
	} return cnt; cnt public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		////////////////////////////////////
		int n = 0;
		int[] A;
		
		n = sc.nextInt();
		A = new int[n];
		
		for (int i = 0; i < n; ++i) {
			A[i] = sc.nextInt();
		}
		
		sort(A, n);
		print(A);
		System.out.println(get());
		
		////////////////////////////////////
		sc.close();
	} main {
		Scanner sc = new Scanner(System.in);
		////////////////////////////////////
		int n = 0;
		int[] A;
		
		n = sc.nextInt();
		A = new int[n];
		
		for (int i = 0; i < n; ++i) {
			A[i] = sc.nextInt();
		}
		
		sort(A, n);
		print(A);
		System.out.println(get());
		
		////////////////////////////////////
		sc.close();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = 0; n 0 int[] A; A n = sc.nextInt() n sc.nextInt() sc.nextInt sc A = new int[n] A new int[n] n for (int i = 0; i < n; ++i) {
			A[i] = sc.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
			A[i] = sc.nextInt();
		} {
			A[i] = sc.nextInt();
		} A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc sort(A, n) sort A n print(A) print A System.out.println(get()) System.out.println System.out System System.out get() get sc.close() sc.close sc String[] args args public class Main {

	// define variables & initialize
	private static int cnt = 0;	// how many bubbleSort is used
	
	// sort method :: sort given array using insertion Sort
	public static void sort(int[] _A, int _n) {
		int flg = 1;
		while (flg != 0) {
			flg = 0;
			for (int i = _n - 1; i >= 1; --i) {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			}
		}
		
	}
	
	// print method :: print array
	public static void print(int[] _A) {
		for (int i = 0; i < _A.length; ++i) {
			System.out.print(_A[i]);
			if (i != _A.length - 1)
				System.out.print(" ");
		}
		System.out.println();
	}
	
	// get method :: get cnt (how many bubbleSort was used)
	public static int get() {
		return cnt;
	}
public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		////////////////////////////////////
		int n = 0;
		int[] A;
		
		n = sc.nextInt();
		A = new int[n];
		
		for (int i = 0; i < n; ++i) {
			A[i] = sc.nextInt();
		}
		
		sort(A, n);
		print(A);
		System.out.println(get());
		
		////////////////////////////////////
		sc.close();
	}



} public class Main {

	// define variables & initialize
	private static int cnt = 0;	// how many bubbleSort is used
	
	// sort method :: sort given array using insertion Sort
	public static void sort(int[] _A, int _n) {
		int flg = 1;
		while (flg != 0) {
			flg = 0;
			for (int i = _n - 1; i >= 1; --i) {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			}
		}
		
	}
	
	// print method :: print array
	public static void print(int[] _A) {
		for (int i = 0; i < _A.length; ++i) {
			System.out.print(_A[i]);
			if (i != _A.length - 1)
				System.out.print(" ");
		}
		System.out.println();
	}
	
	// get method :: get cnt (how many bubbleSort was used)
	public static int get() {
		return cnt;
	}
public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		////////////////////////////////////
		int n = 0;
		int[] A;
		
		n = sc.nextInt();
		A = new int[n];
		
		for (int i = 0; i < n; ++i) {
			A[i] = sc.nextInt();
		}
		
		sort(A, n);
		print(A);
		System.out.println(get());
		
		////////////////////////////////////
		sc.close();
	}



} Main
import java.util.Scanner;

public class Main {

	// define variables & initialize
	private static int cnt = 0;	// how many bubbleSort is used
	
	// sort method :: sort given array using insertion Sort
	public static void sort(int[] _A, int _n) {
		int flg = 1;
		while (flg != 0) {
			flg = 0;
			for (int i = _n - 1; i >= 1; --i) {
				if (_A[i] < _A[i - 1]) {
					_A[i] = _A[i] ^ _A[i - 1];
					_A[i - 1] = _A[i] ^ _A[i - 1];
					_A[i] = _A[i] ^ _A[i - 1];
					flg = 1;
					++cnt;
				}
			}
		}
		
	}
	
	// print method :: print array
	public static void print(int[] _A) {
		for (int i = 0; i < _A.length; ++i) {
			System.out.print(_A[i]);
			if (i != _A.length - 1)
				System.out.print(" ");
		}
		System.out.println();
	}
	
	// get method :: get cnt (how many bubbleSort was used)
	public static int get() {
		return cnt;
	}
public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		////////////////////////////////////
		int n = 0;
		int[] A;
		
		n = sc.nextInt();
		A = new int[n];
		
		for (int i = 0; i < n; ++i) {
			A[i] = sc.nextInt();
		}
		
		sort(A, n);
		print(A);
		System.out.println(get());
		
		////////////////////////////////////
		sc.close();
	}



}