import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = scan.nextInt();
		}
		int count = 0;
		int flag = 1;
		int i = 0;
		while(flag == 1){
			flag = 0;
			for(int j = n-1; j >= i+1; j--){
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			}
			i++;
		}

		for(int j = 0; j < n; j++){
			 System.out.printf(j != n-1? "%d " : "%d\n", arr[j]);
		}
		System.out.printf("%d\n", count);
	}
} import java.util.*; util.* java public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = scan.nextInt();
		}
		int count = 0;
		int flag = 1;
		int i = 0;
		while(flag == 1){
			flag = 0;
			for(int j = n-1; j >= i+1; j--){
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			}
			i++;
		}

		for(int j = 0; j < n; j++){
			 System.out.printf(j != n-1? "%d " : "%d\n", arr[j]);
		}
		System.out.printf("%d\n", count);
	}
} Main private static final Scanner scan = new Scanner(System.in); scan new Scanner(System.in) public static void main(String[] args){
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = scan.nextInt();
		}
		int count = 0;
		int flag = 1;
		int i = 0;
		while(flag == 1){
			flag = 0;
			for(int j = n-1; j >= i+1; j--){
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			}
			i++;
		}

		for(int j = 0; j < n; j++){
			 System.out.printf(j != n-1? "%d " : "%d\n", arr[j]);
		}
		System.out.printf("%d\n", count);
	} main {
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = scan.nextInt();
		}
		int count = 0;
		int flag = 1;
		int i = 0;
		while(flag == 1){
			flag = 0;
			for(int j = n-1; j >= i+1; j--){
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			}
			i++;
		}

		for(int j = 0; j < n; j++){
			 System.out.printf(j != n-1? "%d " : "%d\n", arr[j]);
		}
		System.out.printf("%d\n", count);
	} int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] arr = new int[n]; arr new int[n] n for(int i = 0; i < n; i++){
			arr[i] = scan.nextInt();
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			arr[i] = scan.nextInt();
		} {
			arr[i] = scan.nextInt();
		} arr[i] = scan.nextInt() arr[i] arr i scan.nextInt() scan.nextInt scan int count = 0; count 0 int flag = 1; flag 1 int i = 0; i 0 while(flag == 1){
			flag = 0;
			for(int j = n-1; j >= i+1; j--){
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			}
			i++;
		} flag == 1 flag 1 {
			flag = 0;
			for(int j = n-1; j >= i+1; j--){
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			}
			i++;
		} flag = 0 flag 0 for(int j = n-1; j >= i+1; j--){
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			} int j = n-1; int j = n-1; j n-1 n 1 j >= i+1 j i+1 i 1 j-- j-- j {
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			} {
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			} if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				} arr[j] < arr[j-1] arr[j] arr j arr[j-1] arr j-1 j 1 {
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				} int big = arr[j-1]; big 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] = big arr[j] arr j big count++ count flag = 1 flag 1 i++ i for(int j = 0; j < n; j++){
			 System.out.printf(j != n-1? "%d " : "%d\n", arr[j]);
		} int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
			 System.out.printf(j != n-1? "%d " : "%d\n", arr[j]);
		} {
			 System.out.printf(j != n-1? "%d " : "%d\n", arr[j]);
		} System.out.printf(j != n-1? "%d " : "%d\n", arr[j]) System.out.printf System.out System System.out j != n-1? "%d " : "%d\n" j != n-1 j n-1 n 1 "%d " "%d\n" arr[j] arr j System.out.printf("%d\n", count) System.out.printf System.out System System.out "%d\n" count String[] args args public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = scan.nextInt();
		}
		int count = 0;
		int flag = 1;
		int i = 0;
		while(flag == 1){
			flag = 0;
			for(int j = n-1; j >= i+1; j--){
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			}
			i++;
		}

		for(int j = 0; j < n; j++){
			 System.out.printf(j != n-1? "%d " : "%d\n", arr[j]);
		}
		System.out.printf("%d\n", count);
	}
} public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = scan.nextInt();
		}
		int count = 0;
		int flag = 1;
		int i = 0;
		while(flag == 1){
			flag = 0;
			for(int j = n-1; j >= i+1; j--){
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			}
			i++;
		}

		for(int j = 0; j < n; j++){
			 System.out.printf(j != n-1? "%d " : "%d\n", arr[j]);
		}
		System.out.printf("%d\n", count);
	}
} Main
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in);

	public static void main(String[] args){
		int n = scan.nextInt();
		int[] arr = new int[n];
		for(int i = 0; i < n; i++){
			arr[i] = scan.nextInt();
		}
		int count = 0;
		int flag = 1;
		int i = 0;
		while(flag == 1){
			flag = 0;
			for(int j = n-1; j >= i+1; j--){
				if(arr[j] < arr[j-1]){
					int big = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = big;
					count++;
					flag = 1;
				}
			}
			i++;
		}

		for(int j = 0; j < n; j++){
			 System.out.printf(j != n-1? "%d " : "%d\n", arr[j]);
		}
		System.out.printf("%d\n", count);
	}
}