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


public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????°
		int num = Integer.parseInt(bf.readLine());
		
		//??????????´?
		int[] array = new int[num];
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		for(int i=0;i<num;i++){
			array[i]=Integer.parseInt(arrayString[i]);
		}		
		bubbleSort(array,num);
	}
	
	private static void bubbleSort(int[] array, int num) {
		boolean flag=true;
		int count=0;
		
		while(flag){
			flag=false;
			for(int i=num-1;i>=1;i--){
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			}
		}
		
		for(int i=0;i<array.length;i++){
			System.out.printf("%d",array[i]);
			if(i!=array.length-1){
				System.out.printf(" ");
			}
		}
		System.out.println("");
		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 public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????°
		int num = Integer.parseInt(bf.readLine());
		
		//??????????´?
		int[] array = new int[num];
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		for(int i=0;i<num;i++){
			array[i]=Integer.parseInt(arrayString[i]);
		}		
		bubbleSort(array,num);
	}
	
	private static void bubbleSort(int[] array, int num) {
		boolean flag=true;
		int count=0;
		
		while(flag){
			flag=false;
			for(int i=num-1;i>=1;i--){
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			}
		}
		
		for(int i=0;i<array.length;i++){
			System.out.printf("%d",array[i]);
			if(i!=array.length-1){
				System.out.printf(" ");
			}
		}
		System.out.println("");
		System.out.println(count);
	}
} Main public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????°
		int num = Integer.parseInt(bf.readLine());
		
		//??????????´?
		int[] array = new int[num];
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		for(int i=0;i<num;i++){
			array[i]=Integer.parseInt(arrayString[i]);
		}		
		bubbleSort(array,num);
	} main {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????°
		int num = Integer.parseInt(bf.readLine());
		
		//??????????´?
		int[] array = new int[num];
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		for(int i=0;i<num;i++){
			array[i]=Integer.parseInt(arrayString[i]);
		}		
		bubbleSort(array,num);
	} BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); bf new BufferedReader(new InputStreamReader(System.in)) int num = Integer.parseInt(bf.readLine()); num Integer.parseInt(bf.readLine()) Integer.parseInt Integer bf.readLine() bf.readLine bf int[] array = new int[num]; array new int[num] num String[] arrayString = bf.readLine().split(" "); arrayString bf.readLine().split(" ") bf.readLine().split bf.readLine() bf.readLine bf " " for(int i=0;i<num;i++){
			array[i]=Integer.parseInt(arrayString[i]);
		} int i=0; int i=0; i 0 i<num i num i++ i++ i {
			array[i]=Integer.parseInt(arrayString[i]);
		} {
			array[i]=Integer.parseInt(arrayString[i]);
		} array[i]=Integer.parseInt(arrayString[i]) array[i] array i Integer.parseInt(arrayString[i]) Integer.parseInt Integer arrayString[i] arrayString i bubbleSort(array,num) bubbleSort array num String[] args args private static void bubbleSort(int[] array, int num) {
		boolean flag=true;
		int count=0;
		
		while(flag){
			flag=false;
			for(int i=num-1;i>=1;i--){
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			}
		}
		
		for(int i=0;i<array.length;i++){
			System.out.printf("%d",array[i]);
			if(i!=array.length-1){
				System.out.printf(" ");
			}
		}
		System.out.println("");
		System.out.println(count);
	} bubbleSort {
		boolean flag=true;
		int count=0;
		
		while(flag){
			flag=false;
			for(int i=num-1;i>=1;i--){
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			}
		}
		
		for(int i=0;i<array.length;i++){
			System.out.printf("%d",array[i]);
			if(i!=array.length-1){
				System.out.printf(" ");
			}
		}
		System.out.println("");
		System.out.println(count);
	} boolean flag=true; flag true int count=0; count 0 while(flag){
			flag=false;
			for(int i=num-1;i>=1;i--){
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			}
		} flag {
			flag=false;
			for(int i=num-1;i>=1;i--){
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			}
		} flag=false flag false for(int i=num-1;i>=1;i--){
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			} int i=num-1; int i=num-1; i num-1 num 1 i>=1 i 1 i-- i-- i {
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			} {
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			} if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				} array[i]<array[i-1] array[i] array i array[i-1] array i-1 i 1 {
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				} int tmp=array[i]; tmp array[i] array i array[i]=array[i-1] array[i] array i array[i-1] array i-1 i 1 array[i-1]=tmp array[i-1] array i-1 i 1 tmp flag=true flag true count++ count for(int i=0;i<array.length;i++){
			System.out.printf("%d",array[i]);
			if(i!=array.length-1){
				System.out.printf(" ");
			}
		} int i=0; int i=0; i 0 i<array.length i array.length array array.length i++ i++ i {
			System.out.printf("%d",array[i]);
			if(i!=array.length-1){
				System.out.printf(" ");
			}
		} {
			System.out.printf("%d",array[i]);
			if(i!=array.length-1){
				System.out.printf(" ");
			}
		} System.out.printf("%d",array[i]) System.out.printf System.out System System.out "%d" array[i] array i if(i!=array.length-1){
				System.out.printf(" ");
			} i!=array.length-1 i array.length-1 array.length array array.length 1 {
				System.out.printf(" ");
			} System.out.printf(" ") System.out.printf System.out System System.out " " System.out.println("") System.out.println System.out System System.out "" System.out.println(count) System.out.println System.out System System.out count int[] array array int num num public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????°
		int num = Integer.parseInt(bf.readLine());
		
		//??????????´?
		int[] array = new int[num];
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		for(int i=0;i<num;i++){
			array[i]=Integer.parseInt(arrayString[i]);
		}		
		bubbleSort(array,num);
	}
	
	private static void bubbleSort(int[] array, int num) {
		boolean flag=true;
		int count=0;
		
		while(flag){
			flag=false;
			for(int i=num-1;i>=1;i--){
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			}
		}
		
		for(int i=0;i<array.length;i++){
			System.out.printf("%d",array[i]);
			if(i!=array.length-1){
				System.out.printf(" ");
			}
		}
		System.out.println("");
		System.out.println(count);
	}
} public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????°
		int num = Integer.parseInt(bf.readLine());
		
		//??????????´?
		int[] array = new int[num];
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		for(int i=0;i<num;i++){
			array[i]=Integer.parseInt(arrayString[i]);
		}		
		bubbleSort(array,num);
	}
	
	private static void bubbleSort(int[] array, int num) {
		boolean flag=true;
		int count=0;
		
		while(flag){
			flag=false;
			for(int i=num-1;i>=1;i--){
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			}
		}
		
		for(int i=0;i<array.length;i++){
			System.out.printf("%d",array[i]);
			if(i!=array.length-1){
				System.out.printf(" ");
			}
		}
		System.out.println("");
		System.out.println(count);
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {
	public static void main(String[] args) throws NumberFormatException, IOException {
		//????????????????????????
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		
		//?????°
		int num = Integer.parseInt(bf.readLine());
		
		//??????????´?
		int[] array = new int[num];
		
		//?????????
		String[] arrayString = bf.readLine().split(" ");
		
		for(int i=0;i<num;i++){
			array[i]=Integer.parseInt(arrayString[i]);
		}		
		bubbleSort(array,num);
	}
	
	private static void bubbleSort(int[] array, int num) {
		boolean flag=true;
		int count=0;
		
		while(flag){
			flag=false;
			for(int i=num-1;i>=1;i--){
				if(array[i]<array[i-1]){
					int tmp=array[i];
					array[i]=array[i-1];
					array[i-1]=tmp;
					flag=true;
					count++;
				}
			}
		}
		
		for(int i=0;i<array.length;i++){
			System.out.printf("%d",array[i]);
			if(i!=array.length-1){
				System.out.printf(" ");
			}
		}
		System.out.println("");
		System.out.println(count);
	}
}