import java.util.Scanner;

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

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