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

class Main{

	static int COUNT = 0;

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] input = br.readLine().split(" ");

		for(int i = 0; i < n; i++){
			a[i] = Integer.parseInt(input[i]);
		}

		a = bubbleSort(a, n);

		for(int i = 0; i < n; i++){
			
			System.out.print(a[i]);

			if(i != (n - 1)){
				System.out.print(" ");
			}else{
				System.out.print("\n");
			}

		}

		System.out.println(COUNT);

	}

	static int[] bubbleSort(int[] a, int n){

		for(int j = 0; j < (n - 1); j++){
			for(int i = (n - 1); i > 0; i--){

				if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			}
		}

		return a;

	}

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

	static int COUNT = 0;

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] input = br.readLine().split(" ");

		for(int i = 0; i < n; i++){
			a[i] = Integer.parseInt(input[i]);
		}

		a = bubbleSort(a, n);

		for(int i = 0; i < n; i++){
			
			System.out.print(a[i]);

			if(i != (n - 1)){
				System.out.print(" ");
			}else{
				System.out.print("\n");
			}

		}

		System.out.println(COUNT);

	}

	static int[] bubbleSort(int[] a, int n){

		for(int j = 0; j < (n - 1); j++){
			for(int i = (n - 1); i > 0; i--){

				if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			}
		}

		return a;

	}

} Main static int COUNT = 0; COUNT 0 public static void main(String[] args) throws IOException{

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] input = br.readLine().split(" ");

		for(int i = 0; i < n; i++){
			a[i] = Integer.parseInt(input[i]);
		}

		a = bubbleSort(a, n);

		for(int i = 0; i < n; i++){
			
			System.out.print(a[i]);

			if(i != (n - 1)){
				System.out.print(" ");
			}else{
				System.out.print("\n");
			}

		}

		System.out.println(COUNT);

	} main {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] input = br.readLine().split(" ");

		for(int i = 0; i < n; i++){
			a[i] = Integer.parseInt(input[i]);
		}

		a = bubbleSort(a, n);

		for(int i = 0; i < n; i++){
			
			System.out.print(a[i]);

			if(i != (n - 1)){
				System.out.print(" ");
			}else{
				System.out.print("\n");
			}

		}

		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 int[] a = new int[n]; a new int[n] n String[] input = br.readLine().split(" "); input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int i = 0; i < n; i++){
			a[i] = Integer.parseInt(input[i]);
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			a[i] = Integer.parseInt(input[i]);
		} {
			a[i] = Integer.parseInt(input[i]);
		} a[i] = Integer.parseInt(input[i]) a[i] a i Integer.parseInt(input[i]) Integer.parseInt Integer input[i] input i a = bubbleSort(a, n) a bubbleSort(a, n) bubbleSort a n for(int i = 0; i < n; i++){
			
			System.out.print(a[i]);

			if(i != (n - 1)){
				System.out.print(" ");
			}else{
				System.out.print("\n");
			}

		} 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(" ");
			}else{
				System.out.print("\n");
			}

		} {
			
			System.out.print(a[i]);

			if(i != (n - 1)){
				System.out.print(" ");
			}else{
				System.out.print("\n");
			}

		} System.out.print(a[i]) System.out.print System.out System System.out a[i] a i if(i != (n - 1)){
				System.out.print(" ");
			}else{
				System.out.print("\n");
			} i != (n - 1) i (n - 1) n 1 {
				System.out.print(" ");
			} System.out.print(" ") System.out.print System.out System System.out " " {
				System.out.print("\n");
			} System.out.print("\n") System.out.print System.out System System.out "\n" System.out.println(COUNT) System.out.println System.out System System.out COUNT String[] args args static int[] bubbleSort(int[] a, int n){

		for(int j = 0; j < (n - 1); j++){
			for(int i = (n - 1); i > 0; i--){

				if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			}
		}

		return a;

	} bubbleSort {

		for(int j = 0; j < (n - 1); j++){
			for(int i = (n - 1); i > 0; i--){

				if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			}
		}

		return a;

	} for(int j = 0; j < (n - 1); j++){
			for(int i = (n - 1); i > 0; i--){

				if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			}
		} int j = 0; int j = 0; j 0 j < (n - 1) j (n - 1) n 1 j++ j++ j {
			for(int i = (n - 1); i > 0; i--){

				if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			}
		} {
			for(int i = (n - 1); i > 0; i--){

				if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			}
		} for(int i = (n - 1); i > 0; i--){

				if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			} 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]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			} {

				if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			} if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				} a[i] < a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 {
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				} COUNT++ COUNT int temp = a[i]; temp a[i] a i a[i] = a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 a[i - 1] = temp a[i - 1] a i - 1 i 1 temp return a; a int[] a a int n n
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

class Main{

	static int COUNT = 0;

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		int[] a = new int[n];
		String[] input = br.readLine().split(" ");

		for(int i = 0; i < n; i++){
			a[i] = Integer.parseInt(input[i]);
		}

		a = bubbleSort(a, n);

		for(int i = 0; i < n; i++){
			
			System.out.print(a[i]);

			if(i != (n - 1)){
				System.out.print(" ");
			}else{
				System.out.print("\n");
			}

		}

		System.out.println(COUNT);

	}

	static int[] bubbleSort(int[] a, int n){

		for(int j = 0; j < (n - 1); j++){
			for(int i = (n - 1); i > 0; i--){

				if(a[i] < a[i - 1]){
					COUNT++;
					int temp = a[i];
					a[i] = a[i - 1];
					a[i - 1] = temp;		
				}
				
			}
		}

		return a;

	}

}