import java.util.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] a = new int[n];
	
		for(int i = 0; i < n; i++){
			a[i] = scan.nextInt();
		}
	
		boolean flag = true;
		int swap;
		int count = 0;
		
		while(flag){
			flag = false;
			for(int i = n-1; i >= 1; i--){
				if(a[i] < a[i-1]){
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.print(a[i]);

			if(i != n-1) System.out.print(" ");
		}
		System.out.println();
		System.out.println(count);
	}
} import java.util.Scanner; Scanner java.util class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] a = new int[n];
	
		for(int i = 0; i < n; i++){
			a[i] = scan.nextInt();
		}
	
		boolean flag = true;
		int swap;
		int count = 0;
		
		while(flag){
			flag = false;
			for(int i = n-1; i >= 1; i--){
				if(a[i] < a[i-1]){
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.print(a[i]);

			if(i != n-1) System.out.print(" ");
		}
		System.out.println();
		System.out.println(count);
	}
} Main public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] a = new int[n];
	
		for(int i = 0; i < n; i++){
			a[i] = scan.nextInt();
		}
	
		boolean flag = true;
		int swap;
		int count = 0;
		
		while(flag){
			flag = false;
			for(int i = n-1; i >= 1; i--){
				if(a[i] < a[i-1]){
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.print(a[i]);

			if(i != n-1) System.out.print(" ");
		}
		System.out.println();
		System.out.println(count);
	} main {
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] a = new int[n];
	
		for(int i = 0; i < n; i++){
			a[i] = scan.nextInt();
		}
	
		boolean flag = true;
		int swap;
		int count = 0;
		
		while(flag){
			flag = false;
			for(int i = n-1; i >= 1; i--){
				if(a[i] < a[i-1]){
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.print(a[i]);

			if(i != n-1) System.out.print(" ");
		}
		System.out.println();
		System.out.println(count);
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] a = new int[n]; a new int[n] n for(int i = 0; i < n; i++){
			a[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = scan.nextInt();
		} {
			a[i] = scan.nextInt();
		} a[i] = scan.nextInt() a[i] a i scan.nextInt() scan.nextInt scan boolean flag = true; flag true int swap; swap int count = 0; count 0 while(flag){
			flag = false;
			for(int i = n-1; i >= 1; i--){
				if(a[i] < a[i-1]){
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				}
			}
		} flag {
			flag = false;
			for(int i = n-1; i >= 1; i--){
				if(a[i] < a[i-1]){
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				}
			}
		} flag = false flag false for(int i = n-1; i >= 1; i--){
				if(a[i] < a[i-1]){
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				}
			} 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]){
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				}
			} {
				if(a[i] < a[i-1]){
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				}
			} if(a[i] < a[i-1]){
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				} a[i] < a[i-1] a[i] a i a[i-1] a i-1 i 1 {
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				} swap = a[i] swap a[i] a i a[i] = a[i-1] a[i] a i a[i-1] a i-1 i 1 a[i-1] = swap a[i-1] a i-1 i 1 swap count++ count flag = true flag true for(int i = 0; i < n; i++) {
			System.out.print(a[i]);

			if(i != n-1) System.out.print(" ");
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			System.out.print(a[i]);

			if(i != n-1) System.out.print(" ");
		} {
			System.out.print(a[i]);

			if(i != n-1) System.out.print(" ");
		} System.out.print(a[i]) System.out.print System.out System System.out a[i] a i if(i != n-1) System.out.print(" "); i != n-1 i n-1 n 1 System.out.print(" ") System.out.print System.out System System.out " " 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.Scanner;

class Main {
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);
		
		int n = scan.nextInt();
		int[] a = new int[n];
	
		for(int i = 0; i < n; i++){
			a[i] = scan.nextInt();
		}
	
		boolean flag = true;
		int swap;
		int count = 0;
		
		while(flag){
			flag = false;
			for(int i = n-1; i >= 1; i--){
				if(a[i] < a[i-1]){
					swap = a[i];
					a[i] = a[i-1];
					a[i-1] = swap;
					count++;
					flag = true;
				}
			}
		}
		
		for(int i = 0; i < n; i++) {
			System.out.print(a[i]);

			if(i != n-1) System.out.print(" ");
		}
		System.out.println();
		System.out.println(count);
	}
}