import java.util.Scanner;

public class Main {
	public static void print_arr(int[] arr) {
		int i = 0;
		while(i < arr.length) {
			System.out.print(arr[i]);
			if(i < arr.length - 1) {
				System.out.print(" ");
			}else {
				System.out.print("\n");
			}
			i++;
		}
	}
	public static int bubble_sort(int[] arr) {
		int swap_times = 0;
		int n = arr.length;
		for(int i = 0; i < n; i++) {
			for(int j = n - 1; j >= i+1; j--) {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			}
		}
		
		
		return swap_times;
		
	}
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		
		int n = cin.nextInt();
		int [] arr = new int[n];
		for(int i = 0;  i < n ; i++) {
			arr[i] = cin.nextInt();
		}
		
		int swap_times = bubble_sort(arr);
		print_arr(arr);
		System.out.println(swap_times);
		
		
		
		
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void print_arr(int[] arr) {
		int i = 0;
		while(i < arr.length) {
			System.out.print(arr[i]);
			if(i < arr.length - 1) {
				System.out.print(" ");
			}else {
				System.out.print("\n");
			}
			i++;
		}
	}
	public static int bubble_sort(int[] arr) {
		int swap_times = 0;
		int n = arr.length;
		for(int i = 0; i < n; i++) {
			for(int j = n - 1; j >= i+1; j--) {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			}
		}
		
		
		return swap_times;
		
	}
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		
		int n = cin.nextInt();
		int [] arr = new int[n];
		for(int i = 0;  i < n ; i++) {
			arr[i] = cin.nextInt();
		}
		
		int swap_times = bubble_sort(arr);
		print_arr(arr);
		System.out.println(swap_times);
		
		
		
		
	}
} Main public static void print_arr(int[] arr) {
		int i = 0;
		while(i < arr.length) {
			System.out.print(arr[i]);
			if(i < arr.length - 1) {
				System.out.print(" ");
			}else {
				System.out.print("\n");
			}
			i++;
		}
	} print_arr {
		int i = 0;
		while(i < arr.length) {
			System.out.print(arr[i]);
			if(i < arr.length - 1) {
				System.out.print(" ");
			}else {
				System.out.print("\n");
			}
			i++;
		}
	} int i = 0; i 0 while(i < arr.length) {
			System.out.print(arr[i]);
			if(i < arr.length - 1) {
				System.out.print(" ");
			}else {
				System.out.print("\n");
			}
			i++;
		} i < arr.length i arr.length arr arr.length {
			System.out.print(arr[i]);
			if(i < arr.length - 1) {
				System.out.print(" ");
			}else {
				System.out.print("\n");
			}
			i++;
		} System.out.print(arr[i]) System.out.print System.out System System.out arr[i] arr i if(i < arr.length - 1) {
				System.out.print(" ");
			}else {
				System.out.print("\n");
			} i < arr.length - 1 i arr.length - 1 arr.length arr arr.length 1 {
				System.out.print(" ");
			} System.out.print(" ") System.out.print System.out System System.out " " {
				System.out.print("\n");
			} System.out.print("\n") System.out.print System.out System System.out "\n" i++ i int[] arr arr public static int bubble_sort(int[] arr) {
		int swap_times = 0;
		int n = arr.length;
		for(int i = 0; i < n; i++) {
			for(int j = n - 1; j >= i+1; j--) {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			}
		}
		
		
		return swap_times;
		
	} bubble_sort {
		int swap_times = 0;
		int n = arr.length;
		for(int i = 0; i < n; i++) {
			for(int j = n - 1; j >= i+1; j--) {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			}
		}
		
		
		return swap_times;
		
	} int swap_times = 0; swap_times 0 int n = arr.length; n arr.length arr arr.length for(int i = 0; i < n; i++) {
			for(int j = n - 1; j >= i+1; j--) {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			}
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for(int j = n - 1; j >= i+1; j--) {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			}
		} {
			for(int j = n - 1; j >= i+1; j--) {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			}
		} for(int j = n - 1; j >= i+1; j--) {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			} int j = n - 1; int j = n - 1; j n - 1 n 1 j >= i+1 j i+1 i 1 j-- j-- j {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			} {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			} if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				} arr[j] < arr[j-1] arr[j] arr j arr[j-1] arr j-1 j 1 {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				} swap_times++ swap_times int tmp = arr[j-1]; tmp arr[j-1] arr j-1 j 1 arr[j-1] = arr[j] arr[j-1] arr j-1 j 1 arr[j] arr j arr[j] = tmp arr[j] arr j tmp return swap_times; swap_times int[] arr arr public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		
		int n = cin.nextInt();
		int [] arr = new int[n];
		for(int i = 0;  i < n ; i++) {
			arr[i] = cin.nextInt();
		}
		
		int swap_times = bubble_sort(arr);
		print_arr(arr);
		System.out.println(swap_times);
		
		
		
		
	} main {
		Scanner cin = new Scanner(System.in);
		
		int n = cin.nextInt();
		int [] arr = new int[n];
		for(int i = 0;  i < n ; i++) {
			arr[i] = cin.nextInt();
		}
		
		int swap_times = bubble_sort(arr);
		print_arr(arr);
		System.out.println(swap_times);
		
		
		
		
	} Scanner cin = new Scanner(System.in); cin new Scanner(System.in) int n = cin.nextInt(); n cin.nextInt() cin.nextInt cin int [] arr = new int[n]; arr new int[n] n for(int i = 0;  i < n ; i++) {
			arr[i] = cin.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			arr[i] = cin.nextInt();
		} {
			arr[i] = cin.nextInt();
		} arr[i] = cin.nextInt() arr[i] arr i cin.nextInt() cin.nextInt cin int swap_times = bubble_sort(arr); swap_times bubble_sort(arr) bubble_sort arr print_arr(arr) print_arr arr System.out.println(swap_times) System.out.println System.out System System.out swap_times String[] args args public class Main {
	public static void print_arr(int[] arr) {
		int i = 0;
		while(i < arr.length) {
			System.out.print(arr[i]);
			if(i < arr.length - 1) {
				System.out.print(" ");
			}else {
				System.out.print("\n");
			}
			i++;
		}
	}
	public static int bubble_sort(int[] arr) {
		int swap_times = 0;
		int n = arr.length;
		for(int i = 0; i < n; i++) {
			for(int j = n - 1; j >= i+1; j--) {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			}
		}
		
		
		return swap_times;
		
	}
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		
		int n = cin.nextInt();
		int [] arr = new int[n];
		for(int i = 0;  i < n ; i++) {
			arr[i] = cin.nextInt();
		}
		
		int swap_times = bubble_sort(arr);
		print_arr(arr);
		System.out.println(swap_times);
		
		
		
		
	}
} public class Main {
	public static void print_arr(int[] arr) {
		int i = 0;
		while(i < arr.length) {
			System.out.print(arr[i]);
			if(i < arr.length - 1) {
				System.out.print(" ");
			}else {
				System.out.print("\n");
			}
			i++;
		}
	}
	public static int bubble_sort(int[] arr) {
		int swap_times = 0;
		int n = arr.length;
		for(int i = 0; i < n; i++) {
			for(int j = n - 1; j >= i+1; j--) {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			}
		}
		
		
		return swap_times;
		
	}
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		
		int n = cin.nextInt();
		int [] arr = new int[n];
		for(int i = 0;  i < n ; i++) {
			arr[i] = cin.nextInt();
		}
		
		int swap_times = bubble_sort(arr);
		print_arr(arr);
		System.out.println(swap_times);
		
		
		
		
	}
} Main
import java.util.Scanner;

public class Main {
	public static void print_arr(int[] arr) {
		int i = 0;
		while(i < arr.length) {
			System.out.print(arr[i]);
			if(i < arr.length - 1) {
				System.out.print(" ");
			}else {
				System.out.print("\n");
			}
			i++;
		}
	}
	public static int bubble_sort(int[] arr) {
		int swap_times = 0;
		int n = arr.length;
		for(int i = 0; i < n; i++) {
			for(int j = n - 1; j >= i+1; j--) {
				// do swapping
				if(arr[j] < arr[j-1]) {
					swap_times++;
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
				}
			}
		}
		
		
		return swap_times;
		
	}
	
	public static void main(String[] args) {
		Scanner cin = new Scanner(System.in);
		
		int n = cin.nextInt();
		int [] arr = new int[n];
		for(int i = 0;  i < n ; i++) {
			arr[i] = cin.nextInt();
		}
		
		int swap_times = bubble_sort(arr);
		print_arr(arr);
		System.out.println(swap_times);
		
		
		
		
	}
}