import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int min, mini = 0, count = 0, a;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		scan.close();
		
		for (int i = 0; i < n - 1; i++) {
			min = data[i];
			for (int j = i + 1; j < n; j++) {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			}
			
			if (min != data[i]) {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			}	
		}
		
		for (int i = 0; i < n; i++) {
			if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			}
		}
		
		
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int min, mini = 0, count = 0, a;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		scan.close();
		
		for (int i = 0; i < n - 1; i++) {
			min = data[i];
			for (int j = i + 1; j < n; j++) {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			}
			
			if (min != data[i]) {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			}	
		}
		
		for (int i = 0; i < n; i++) {
			if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			}
		}
		
		
	}
} Main public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int min, mini = 0, count = 0, a;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		scan.close();
		
		for (int i = 0; i < n - 1; i++) {
			min = data[i];
			for (int j = i + 1; j < n; j++) {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			}
			
			if (min != data[i]) {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			}	
		}
		
		for (int i = 0; i < n; i++) {
			if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			}
		}
		
		
	} main {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int min, mini = 0, count = 0, a;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		scan.close();
		
		for (int i = 0; i < n - 1; i++) {
			min = data[i];
			for (int j = i + 1; j < n; j++) {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			}
			
			if (min != data[i]) {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			}	
		}
		
		for (int i = 0; i < n; i++) {
			if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			}
		}
		
		
	} Scanner scan = new Scanner (System.in); scan new Scanner (System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int data[] = new int[n]; data new int[n] n int min min mini = 0 mini 0 count = 0 count 0 a; a for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			data[i] = scan.nextInt();
		} {
			data[i] = scan.nextInt();
		} data[i] = scan.nextInt() data[i] data i scan.nextInt() scan.nextInt scan scan.close() scan.close scan for (int i = 0; i < n - 1; i++) {
			min = data[i];
			for (int j = i + 1; j < n; j++) {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			}
			
			if (min != data[i]) {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			}	
		} int i = 0; int i = 0; i 0 i < n - 1 i n - 1 n 1 i++ i++ i {
			min = data[i];
			for (int j = i + 1; j < n; j++) {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			}
			
			if (min != data[i]) {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			}	
		} {
			min = data[i];
			for (int j = i + 1; j < n; j++) {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			}
			
			if (min != data[i]) {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			}	
		} min = data[i] min data[i] data i for (int j = i + 1; j < n; j++) {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			} int j = i + 1; int j = i + 1; j i + 1 i 1 j < n j n j++ j++ j {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			} {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			} if (min > data[j]) {
					min = data[j];
					mini = j;
				} min > data[j] min data[j] data j {
					min = data[j];
					mini = j;
				} min = data[j] min data[j] data j mini = j mini j if (min != data[i]) {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			} min != data[i] min data[i] data i {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			} for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				} int k = mini; int k = mini; k mini k > i k i k-- k-- k {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				} {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				} a = data[k - 1] a data[k - 1] data k - 1 k 1 data[k - 1] = data[k] data[k - 1] data k - 1 k 1 data[k] data k data[k] = a data[k] data k a count++ count for (int i = 0; i < n; i++) {
			if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			}
		} {
			if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			}
		} if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			} i == n - 1 i n - 1 n 1 {
				System.out.println(data[i]);
				System.out.println(count);
			} System.out.println(data[i]) System.out.println System.out System System.out data[i] data i System.out.println(count) System.out.println System.out System System.out count {
				System.out.print(data[i] + " ");
			} System.out.print(data[i] + " ") System.out.print System.out System System.out data[i] + " " data[i] data i " " String [] args args public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int min, mini = 0, count = 0, a;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		scan.close();
		
		for (int i = 0; i < n - 1; i++) {
			min = data[i];
			for (int j = i + 1; j < n; j++) {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			}
			
			if (min != data[i]) {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			}	
		}
		
		for (int i = 0; i < n; i++) {
			if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			}
		}
		
		
	}
} public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int min, mini = 0, count = 0, a;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		scan.close();
		
		for (int i = 0; i < n - 1; i++) {
			min = data[i];
			for (int j = i + 1; j < n; j++) {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			}
			
			if (min != data[i]) {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			}	
		}
		
		for (int i = 0; i < n; i++) {
			if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			}
		}
		
		
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main (String [] args) {
		Scanner scan = new Scanner (System.in);
		int n = scan.nextInt();
		int data[] = new int[n];
		int min, mini = 0, count = 0, a;
		
		for (int i = 0; i < n; i++) {
			data[i] = scan.nextInt();
		}
		scan.close();
		
		for (int i = 0; i < n - 1; i++) {
			min = data[i];
			for (int j = i + 1; j < n; j++) {
				if (min > data[j]) {
					min = data[j];
					mini = j;
				}
			}
			
			if (min != data[i]) {
				for (int k = mini; k > i; k--) {
					a = data[k - 1];
					data[k - 1] = data[k];
					data[k] = a;
					count++;
				}
			}	
		}
		
		for (int i = 0; i < n; i++) {
			if (i == n - 1) {
				System.out.println(data[i]);
				System.out.println(count);
			} else {
				System.out.print(data[i] + " ");
			}
		}
		
		
	}
}

