import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String[] s_nums = br.readLine().split(" ");

		int[] nums = new int[s_nums.length];

		for (int i = 0; i < n; i++) {
			nums[i] = Integer.parseInt(s_nums[i]);

		}

		boolean jeudge = true;

		int count =0;

		while(jeudge){
			jeudge = false;
			for(int k = nums.length-1; k>=1; k--){

				if(nums[k]<nums[k-1]){
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<n; i++){
			sb.append(nums[i]);
			sb.append(" ");
		}

		System.out.println(sb.toString().trim());
		System.out.println(count);
	}


} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String[] s_nums = br.readLine().split(" ");

		int[] nums = new int[s_nums.length];

		for (int i = 0; i < n; i++) {
			nums[i] = Integer.parseInt(s_nums[i]);

		}

		boolean jeudge = true;

		int count =0;

		while(jeudge){
			jeudge = false;
			for(int k = nums.length-1; k>=1; k--){

				if(nums[k]<nums[k-1]){
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<n; i++){
			sb.append(nums[i]);
			sb.append(" ");
		}

		System.out.println(sb.toString().trim());
		System.out.println(count);
	}


} Main public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String[] s_nums = br.readLine().split(" ");

		int[] nums = new int[s_nums.length];

		for (int i = 0; i < n; i++) {
			nums[i] = Integer.parseInt(s_nums[i]);

		}

		boolean jeudge = true;

		int count =0;

		while(jeudge){
			jeudge = false;
			for(int k = nums.length-1; k>=1; k--){

				if(nums[k]<nums[k-1]){
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<n; i++){
			sb.append(nums[i]);
			sb.append(" ");
		}

		System.out.println(sb.toString().trim());
		System.out.println(count);
	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String[] s_nums = br.readLine().split(" ");

		int[] nums = new int[s_nums.length];

		for (int i = 0; i < n; i++) {
			nums[i] = Integer.parseInt(s_nums[i]);

		}

		boolean jeudge = true;

		int count =0;

		while(jeudge){
			jeudge = false;
			for(int k = nums.length-1; k>=1; k--){

				if(nums[k]<nums[k-1]){
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<n; i++){
			sb.append(nums[i]);
			sb.append(" ");
		}

		System.out.println(sb.toString().trim());
		System.out.println(count);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br String[] s_nums = br.readLine().split(" "); s_nums br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int[] nums = new int[s_nums.length]; nums new int[s_nums.length] s_nums.length s_nums s_nums.length for (int i = 0; i < n; i++) {
			nums[i] = Integer.parseInt(s_nums[i]);

		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			nums[i] = Integer.parseInt(s_nums[i]);

		} {
			nums[i] = Integer.parseInt(s_nums[i]);

		} nums[i] = Integer.parseInt(s_nums[i]) nums[i] nums i Integer.parseInt(s_nums[i]) Integer.parseInt Integer s_nums[i] s_nums i boolean jeudge = true; jeudge true int count =0; count 0 while(jeudge){
			jeudge = false;
			for(int k = nums.length-1; k>=1; k--){

				if(nums[k]<nums[k-1]){
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				}
			}
		} jeudge {
			jeudge = false;
			for(int k = nums.length-1; k>=1; k--){

				if(nums[k]<nums[k-1]){
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				}
			}
		} jeudge = false jeudge false for(int k = nums.length-1; k>=1; k--){

				if(nums[k]<nums[k-1]){
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				}
			} int k = nums.length-1; int k = nums.length-1; k nums.length-1 nums.length nums nums.length 1 k>=1 k 1 k-- k-- k {

				if(nums[k]<nums[k-1]){
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				}
			} {

				if(nums[k]<nums[k-1]){
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				}
			} if(nums[k]<nums[k-1]){
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				} nums[k]<nums[k-1] nums[k] nums k nums[k-1] nums k-1 k 1 {
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				} int a = nums[k]; a nums[k] nums k nums[k] =nums[k-1] nums[k] nums k nums[k-1] nums k-1 k 1 nums[k-1] =a nums[k-1] nums k-1 k 1 a count++ count jeudge = true jeudge true StringBuilder sb = new StringBuilder(); sb new StringBuilder() for(int i=0; i<n; i++){
			sb.append(nums[i]);
			sb.append(" ");
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			sb.append(nums[i]);
			sb.append(" ");
		} {
			sb.append(nums[i]);
			sb.append(" ");
		} sb.append(nums[i]) sb.append sb nums[i] nums i sb.append(" ") sb.append sb " " System.out.println(sb.toString().trim()) System.out.println System.out System System.out sb.toString().trim() sb.toString().trim sb.toString() sb.toString sb System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		int n = Integer.parseInt(br.readLine());

		String[] s_nums = br.readLine().split(" ");

		int[] nums = new int[s_nums.length];

		for (int i = 0; i < n; i++) {
			nums[i] = Integer.parseInt(s_nums[i]);

		}

		boolean jeudge = true;

		int count =0;

		while(jeudge){
			jeudge = false;
			for(int k = nums.length-1; k>=1; k--){

				if(nums[k]<nums[k-1]){
					int a = nums[k];

					nums[k] =nums[k-1];

					nums[k-1] =a;

					count++;

					jeudge = true;
				}
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int i=0; i<n; i++){
			sb.append(nums[i]);
			sb.append(" ");
		}

		System.out.println(sb.toString().trim());
		System.out.println(count);
	}


}