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

public class Main{
	static int N;
	static int [] A;
	static int max;
	static int count;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		N = Integer.parseInt(br.readLine());
		String [] temp = br.readLine().split(" ");
		max = temp.length;
		A = new int[max];
		for(int i=0;i < max;i++){
			A[i] = Integer.parseInt(temp[i]);
		}

		for(int i=0;i < max;i++){
			sort();
		}

		for(int i=0;i < max-1;i++){
			System.out.print(A[i]+" ");
		}
		System.out.println(A[max-1]);
		System.out.println(count);
	}

	public static void sort(){
		for(int i=max-1;i>0;i--){
			if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			}


		}
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main{
	static int N;
	static int [] A;
	static int max;
	static int count;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		N = Integer.parseInt(br.readLine());
		String [] temp = br.readLine().split(" ");
		max = temp.length;
		A = new int[max];
		for(int i=0;i < max;i++){
			A[i] = Integer.parseInt(temp[i]);
		}

		for(int i=0;i < max;i++){
			sort();
		}

		for(int i=0;i < max-1;i++){
			System.out.print(A[i]+" ");
		}
		System.out.println(A[max-1]);
		System.out.println(count);
	}

	public static void sort(){
		for(int i=max-1;i>0;i--){
			if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			}


		}
	}

} Main static int N; N static int [] A; A static int max; max static int count; count public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		N = Integer.parseInt(br.readLine());
		String [] temp = br.readLine().split(" ");
		max = temp.length;
		A = new int[max];
		for(int i=0;i < max;i++){
			A[i] = Integer.parseInt(temp[i]);
		}

		for(int i=0;i < max;i++){
			sort();
		}

		for(int i=0;i < max-1;i++){
			System.out.print(A[i]+" ");
		}
		System.out.println(A[max-1]);
		System.out.println(count);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		N = Integer.parseInt(br.readLine());
		String [] temp = br.readLine().split(" ");
		max = temp.length;
		A = new int[max];
		for(int i=0;i < max;i++){
			A[i] = Integer.parseInt(temp[i]);
		}

		for(int i=0;i < max;i++){
			sort();
		}

		for(int i=0;i < max-1;i++){
			System.out.print(A[i]+" ");
		}
		System.out.println(A[max-1]);
		System.out.println(count);
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) N = Integer.parseInt(br.readLine()) N Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br String [] temp = br.readLine().split(" "); temp br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " max = temp.length max temp.length temp temp.length A = new int[max] A new int[max] max for(int i=0;i < max;i++){
			A[i] = Integer.parseInt(temp[i]);
		} int i=0; int i=0; i 0 i < max i max i++ i++ i {
			A[i] = Integer.parseInt(temp[i]);
		} {
			A[i] = Integer.parseInt(temp[i]);
		} A[i] = Integer.parseInt(temp[i]) A[i] A i Integer.parseInt(temp[i]) Integer.parseInt Integer temp[i] temp i for(int i=0;i < max;i++){
			sort();
		} int i=0; int i=0; i 0 i < max i max i++ i++ i {
			sort();
		} {
			sort();
		} sort() sort for(int i=0;i < max-1;i++){
			System.out.print(A[i]+" ");
		} int i=0; int i=0; i 0 i < max-1 i max-1 max 1 i++ i++ i {
			System.out.print(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(A[max-1]) System.out.println System.out System System.out A[max-1] A max-1 max 1 System.out.println(count) System.out.println System.out System System.out count String[] args args public static void sort(){
		for(int i=max-1;i>0;i--){
			if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			}


		}
	} sort {
		for(int i=max-1;i>0;i--){
			if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			}


		}
	} for(int i=max-1;i>0;i--){
			if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			}


		} int i=max-1; int i=max-1; i max-1 max 1 i>0 i 0 i-- i-- i {
			if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			}


		} {
			if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			}


		} if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			} A[i] >= A[i-1] A[i] A i A[i-1] A i-1 i 1 {
				continue;
			} continue; {
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			} int num = A[i]; num A[i] A i A[i] = A[i-1] A[i] A i A[i-1] A i-1 i 1 A[i-1] = num A[i-1] A i-1 i 1 num count++ count public class Main{
	static int N;
	static int [] A;
	static int max;
	static int count;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		N = Integer.parseInt(br.readLine());
		String [] temp = br.readLine().split(" ");
		max = temp.length;
		A = new int[max];
		for(int i=0;i < max;i++){
			A[i] = Integer.parseInt(temp[i]);
		}

		for(int i=0;i < max;i++){
			sort();
		}

		for(int i=0;i < max-1;i++){
			System.out.print(A[i]+" ");
		}
		System.out.println(A[max-1]);
		System.out.println(count);
	}

	public static void sort(){
		for(int i=max-1;i>0;i--){
			if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			}


		}
	}

} public class Main{
	static int N;
	static int [] A;
	static int max;
	static int count;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		N = Integer.parseInt(br.readLine());
		String [] temp = br.readLine().split(" ");
		max = temp.length;
		A = new int[max];
		for(int i=0;i < max;i++){
			A[i] = Integer.parseInt(temp[i]);
		}

		for(int i=0;i < max;i++){
			sort();
		}

		for(int i=0;i < max-1;i++){
			System.out.print(A[i]+" ");
		}
		System.out.println(A[max-1]);
		System.out.println(count);
	}

	public static void sort(){
		for(int i=max-1;i>0;i--){
			if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			}


		}
	}

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

public class Main{
	static int N;
	static int [] A;
	static int max;
	static int count;
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		N = Integer.parseInt(br.readLine());
		String [] temp = br.readLine().split(" ");
		max = temp.length;
		A = new int[max];
		for(int i=0;i < max;i++){
			A[i] = Integer.parseInt(temp[i]);
		}

		for(int i=0;i < max;i++){
			sort();
		}

		for(int i=0;i < max-1;i++){
			System.out.print(A[i]+" ");
		}
		System.out.println(A[max-1]);
		System.out.println(count);
	}

	public static void sort(){
		for(int i=max-1;i>0;i--){
			if(A[i] >= A[i-1]){
				continue;
			}
			else{
				int num = A[i];
				A[i] = A[i-1];
				A[i-1] = num;
				count++;
			}


		}
	}

}