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

import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.Deque;

public 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 tmp_arr[] = new String[n];
		int arr[] = new int[n];
		tmp_arr = br.readLine().split(" ");
		for(int i=0; i<n;i++){
			arr[i] = Integer.parseInt(tmp_arr[i]);
		}
		
		bubblesort_swap_num(arr);
	}
	public static void bubblesort_swap_num(int[] arr){
		int n = arr.length;
		int ans = 0;
		for(int i=0; i<n; i++){
			for(int j=1; j<n-i; j++){
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			}
		}
		print_array(arr);
		System.out.println(ans);
	}
	
	public static void print_array(int[] arr){
		for(int i=0; i<arr.length; i++){
			System.out.print(arr[i]);
			if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n");
		}
	}
}
 import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util import java.util.ArrayDeque; ArrayDeque java.util import java.util.Deque; Deque java.util public 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 tmp_arr[] = new String[n];
		int arr[] = new int[n];
		tmp_arr = br.readLine().split(" ");
		for(int i=0; i<n;i++){
			arr[i] = Integer.parseInt(tmp_arr[i]);
		}
		
		bubblesort_swap_num(arr);
	}
	public static void bubblesort_swap_num(int[] arr){
		int n = arr.length;
		int ans = 0;
		for(int i=0; i<n; i++){
			for(int j=1; j<n-i; j++){
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			}
		}
		print_array(arr);
		System.out.println(ans);
	}
	
	public static void print_array(int[] arr){
		for(int i=0; i<arr.length; i++){
			System.out.print(arr[i]);
			if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n");
		}
	}
} Main public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String tmp_arr[] = new String[n];
		int arr[] = new int[n];
		tmp_arr = br.readLine().split(" ");
		for(int i=0; i<n;i++){
			arr[i] = Integer.parseInt(tmp_arr[i]);
		}
		
		bubblesort_swap_num(arr);
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		String tmp_arr[] = new String[n];
		int arr[] = new int[n];
		tmp_arr = br.readLine().split(" ");
		for(int i=0; i<n;i++){
			arr[i] = Integer.parseInt(tmp_arr[i]);
		}
		
		bubblesort_swap_num(arr);
	} 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 tmp_arr[] = new String[n]; tmp_arr new String[n] n int arr[] = new int[n]; arr new int[n] n tmp_arr = br.readLine().split(" ") tmp_arr br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int i=0; i<n;i++){
			arr[i] = Integer.parseInt(tmp_arr[i]);
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			arr[i] = Integer.parseInt(tmp_arr[i]);
		} {
			arr[i] = Integer.parseInt(tmp_arr[i]);
		} arr[i] = Integer.parseInt(tmp_arr[i]) arr[i] arr i Integer.parseInt(tmp_arr[i]) Integer.parseInt Integer tmp_arr[i] tmp_arr i bubblesort_swap_num(arr) bubblesort_swap_num arr String[] args args public static void bubblesort_swap_num(int[] arr){
		int n = arr.length;
		int ans = 0;
		for(int i=0; i<n; i++){
			for(int j=1; j<n-i; j++){
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			}
		}
		print_array(arr);
		System.out.println(ans);
	} bubblesort_swap_num {
		int n = arr.length;
		int ans = 0;
		for(int i=0; i<n; i++){
			for(int j=1; j<n-i; j++){
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			}
		}
		print_array(arr);
		System.out.println(ans);
	} int n = arr.length; n arr.length arr arr.length int ans = 0; ans 0 for(int i=0; i<n; i++){
			for(int j=1; j<n-i; j++){
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			}
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			for(int j=1; j<n-i; j++){
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			}
		} {
			for(int j=1; j<n-i; j++){
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			}
		} for(int j=1; j<n-i; j++){
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			} int j=1; int j=1; j 1 j<n-i j n-i n i j++ j++ j {
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			} {
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			} if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				} arr[j-1] > arr[j] arr[j-1] arr j-1 j 1 arr[j] arr j {
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				} int tmp = arr[j-1]; tmp 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] = tmp arr[j] arr j tmp ans++ ans print_array(arr) print_array arr System.out.println(ans) System.out.println System.out System System.out ans int[] arr arr public static void print_array(int[] arr){
		for(int i=0; i<arr.length; i++){
			System.out.print(arr[i]);
			if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n");
		}
	} print_array {
		for(int i=0; i<arr.length; i++){
			System.out.print(arr[i]);
			if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n");
		}
	} for(int i=0; i<arr.length; i++){
			System.out.print(arr[i]);
			if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n");
		} int i=0; int i=0; i 0 i<arr.length i arr.length arr arr.length i++ i++ i {
			System.out.print(arr[i]);
			if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n");
		} {
			System.out.print(arr[i]);
			if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n");
		} System.out.print(arr[i]) System.out.print System.out System System.out arr[i] arr i if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n"); i != arr.length-1 i arr.length-1 arr.length arr arr.length 1 System.out.print(" ") System.out.print System.out System System.out " " System.out.print("\n") System.out.print System.out System System.out "\n" int[] arr arr public 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 tmp_arr[] = new String[n];
		int arr[] = new int[n];
		tmp_arr = br.readLine().split(" ");
		for(int i=0; i<n;i++){
			arr[i] = Integer.parseInt(tmp_arr[i]);
		}
		
		bubblesort_swap_num(arr);
	}
	public static void bubblesort_swap_num(int[] arr){
		int n = arr.length;
		int ans = 0;
		for(int i=0; i<n; i++){
			for(int j=1; j<n-i; j++){
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			}
		}
		print_array(arr);
		System.out.println(ans);
	}
	
	public static void print_array(int[] arr){
		for(int i=0; i<arr.length; i++){
			System.out.print(arr[i]);
			if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n");
		}
	}
} public 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 tmp_arr[] = new String[n];
		int arr[] = new int[n];
		tmp_arr = br.readLine().split(" ");
		for(int i=0; i<n;i++){
			arr[i] = Integer.parseInt(tmp_arr[i]);
		}
		
		bubblesort_swap_num(arr);
	}
	public static void bubblesort_swap_num(int[] arr){
		int n = arr.length;
		int ans = 0;
		for(int i=0; i<n; i++){
			for(int j=1; j<n-i; j++){
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			}
		}
		print_array(arr);
		System.out.println(ans);
	}
	
	public static void print_array(int[] arr){
		for(int i=0; i<arr.length; i++){
			System.out.print(arr[i]);
			if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n");
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

import java.util.Scanner;
import java.util.ArrayDeque;
import java.util.Deque;

public 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 tmp_arr[] = new String[n];
		int arr[] = new int[n];
		tmp_arr = br.readLine().split(" ");
		for(int i=0; i<n;i++){
			arr[i] = Integer.parseInt(tmp_arr[i]);
		}
		
		bubblesort_swap_num(arr);
	}
	public static void bubblesort_swap_num(int[] arr){
		int n = arr.length;
		int ans = 0;
		for(int i=0; i<n; i++){
			for(int j=1; j<n-i; j++){
				if(arr[j-1] > arr[j]){
					int tmp = arr[j-1];
					arr[j-1] = arr[j];
					arr[j] = tmp;
					ans++;
				}
			}
		}
		print_array(arr);
		System.out.println(ans);
	}
	
	public static void print_array(int[] arr){
		for(int i=0; i<arr.length; i++){
			System.out.print(arr[i]);
			if(i != arr.length-1) System.out.print(" ");
			else System.out.print("\n");
		}
	}
}

