import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]) {
		
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i=0; i<n; i++) list.add(sc.nextInt());
		
		
		int count = 0;
		for (int i=0; i<n-1; i++) {
			
			for (int j=0; j<n-i-1; j++) {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			}
			
		}
		
		for (int i=0; i<n; i++) {
			System.out.print((i==0?"":" ")+list.get(i));
		}
		System.out.println();
		System.out.println(count);
		
	}
} import java.util.*; util.* java class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]) {
		
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i=0; i<n; i++) list.add(sc.nextInt());
		
		
		int count = 0;
		for (int i=0; i<n-1; i++) {
			
			for (int j=0; j<n-i-1; j++) {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			}
			
		}
		
		for (int i=0; i<n; i++) {
			System.out.print((i==0?"":" ")+list.get(i));
		}
		System.out.println();
		System.out.println(count);
		
	}
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) public static void main(String args[]) {
		
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i=0; i<n; i++) list.add(sc.nextInt());
		
		
		int count = 0;
		for (int i=0; i<n-1; i++) {
			
			for (int j=0; j<n-i-1; j++) {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			}
			
		}
		
		for (int i=0; i<n; i++) {
			System.out.print((i==0?"":" ")+list.get(i));
		}
		System.out.println();
		System.out.println(count);
		
	} main {
		
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i=0; i<n; i++) list.add(sc.nextInt());
		
		
		int count = 0;
		for (int i=0; i<n-1; i++) {
			
			for (int j=0; j<n-i-1; j++) {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			}
			
		}
		
		for (int i=0; i<n; i++) {
			System.out.print((i==0?"":" ")+list.get(i));
		}
		System.out.println();
		System.out.println(count);
		
	} int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc ArrayList<Integer> list = new ArrayList<>(); list new ArrayList<>() for (int i=0; i<n; i++) list.add(sc.nextInt()); int i=0; int i=0; i 0 i<n i n i++ i++ i list.add(sc.nextInt()); list.add(sc.nextInt()) list.add list sc.nextInt() sc.nextInt sc int count = 0; count 0 for (int i=0; i<n-1; i++) {
			
			for (int j=0; j<n-i-1; j++) {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			}
			
		} int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
			
			for (int j=0; j<n-i-1; j++) {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			}
			
		} {
			
			for (int j=0; j<n-i-1; j++) {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			}
			
		} for (int j=0; j<n-i-1; j++) {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			} int j=0; int j=0; j 0 j<n-i-1 j n-i-1 n-i-1 n i 1 j++ j++ j {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			} {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			} if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				} list.get(j) > list.get(j+1) list.get(j) list.get list j list.get(j+1) list.get list j+1 j 1 {
					Collections.swap(list, j, j+1);
					count++;
				} Collections.swap(list, j, j+1) Collections.swap Collections list j j+1 j 1 count++ count for (int i=0; i<n; i++) {
			System.out.print((i==0?"":" ")+list.get(i));
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			System.out.print((i==0?"":" ")+list.get(i));
		} {
			System.out.print((i==0?"":" ")+list.get(i));
		} System.out.print((i==0?"":" ")+list.get(i)) System.out.print System.out System System.out (i==0?"":" ")+list.get(i) (i==0?"":" ") i==0 i 0 "" " " list.get(i) list.get list i System.out.println() System.out.println System.out System System.out System.out.println(count) System.out.println System.out System System.out count String args[] args
import java.util.*;

class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]) {
		
		int n = sc.nextInt();
		ArrayList<Integer> list = new ArrayList<>();
		for (int i=0; i<n; i++) list.add(sc.nextInt());
		
		
		int count = 0;
		for (int i=0; i<n-1; i++) {
			
			for (int j=0; j<n-i-1; j++) {
				if (list.get(j) > list.get(j+1)) {
					Collections.swap(list, j, j+1);
					count++;
				}
			}
			
		}
		
		for (int i=0; i<n; i++) {
			System.out.print((i==0?"":" ")+list.get(i));
		}
		System.out.println();
		System.out.println(count);
		
	}
}
