import java.util.Scanner;

public class Main{


	public static void BubbleSort(int[] array){
		int len=array.length;
		int cnt=0;
		int swap;
		for(int i=0;i<len-1;i++){
			for(int j=len-1;i<j;j--){
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			}
		}
		for(int i=0;i<len;i++){
		System.out.print(array[i]);
		if(i!=len-1)System.out.print(" ");}

		System.out.println();
		System.out.println(cnt);
	}

	public static void main(String[] args){

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		BubbleSort(box);

		scan.close();

	}

} import java.util.Scanner; Scanner java.util public class Main{


	public static void BubbleSort(int[] array){
		int len=array.length;
		int cnt=0;
		int swap;
		for(int i=0;i<len-1;i++){
			for(int j=len-1;i<j;j--){
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			}
		}
		for(int i=0;i<len;i++){
		System.out.print(array[i]);
		if(i!=len-1)System.out.print(" ");}

		System.out.println();
		System.out.println(cnt);
	}

	public static void main(String[] args){

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		BubbleSort(box);

		scan.close();

	}

} Main public static void BubbleSort(int[] array){
		int len=array.length;
		int cnt=0;
		int swap;
		for(int i=0;i<len-1;i++){
			for(int j=len-1;i<j;j--){
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			}
		}
		for(int i=0;i<len;i++){
		System.out.print(array[i]);
		if(i!=len-1)System.out.print(" ");}

		System.out.println();
		System.out.println(cnt);
	} BubbleSort {
		int len=array.length;
		int cnt=0;
		int swap;
		for(int i=0;i<len-1;i++){
			for(int j=len-1;i<j;j--){
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			}
		}
		for(int i=0;i<len;i++){
		System.out.print(array[i]);
		if(i!=len-1)System.out.print(" ");}

		System.out.println();
		System.out.println(cnt);
	} int len=array.length; len array.length array array.length int cnt=0; cnt 0 int swap; swap for(int i=0;i<len-1;i++){
			for(int j=len-1;i<j;j--){
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			}
		} int i=0; int i=0; i 0 i<len-1 i len-1 len 1 i++ i++ i {
			for(int j=len-1;i<j;j--){
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			}
		} {
			for(int j=len-1;i<j;j--){
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			}
		} for(int j=len-1;i<j;j--){
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			} int j=len-1; int j=len-1; j len-1 len 1 i<j i j j-- j-- j {
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			} {
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			} if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				} array[j]<array[j-1] array[j] array j array[j-1] array j-1 j 1 {
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				} cnt++ cnt swap=array[j] swap array[j] array j array[j]=array[j-1] array[j] array j array[j-1] array j-1 j 1 array[j-1]=swap array[j-1] array j-1 j 1 swap for(int i=0;i<len;i++){
		System.out.print(array[i]);
		if(i!=len-1)System.out.print(" ");} int i=0; int i=0; i 0 i<len i len i++ i++ i {
		System.out.print(array[i]);
		if(i!=len-1)System.out.print(" ");} {
		System.out.print(array[i]);
		if(i!=len-1)System.out.print(" ");} System.out.print(array[i]) System.out.print System.out System System.out array[i] array i if(i!=len-1)System.out.print(" "); i!=len-1 i len-1 len 1 System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out System.out.println(cnt) System.out.println System.out System System.out cnt int[] array array public static void main(String[] args){

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		BubbleSort(box);

		scan.close();

	} main {

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		BubbleSort(box);

		scan.close();

	} int n; n Scanner scan=new Scanner(System.in); scan new Scanner(System.in) n=scan.nextInt() n scan.nextInt() scan.nextInt scan int[] box=new int[n]; box new int[n] n for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
		box[i]=scan.nextInt();
		} {
		box[i]=scan.nextInt();
		} box[i]=scan.nextInt() box[i] box i scan.nextInt() scan.nextInt scan BubbleSort(box) BubbleSort box scan.close() scan.close scan String[] args args public class Main{


	public static void BubbleSort(int[] array){
		int len=array.length;
		int cnt=0;
		int swap;
		for(int i=0;i<len-1;i++){
			for(int j=len-1;i<j;j--){
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			}
		}
		for(int i=0;i<len;i++){
		System.out.print(array[i]);
		if(i!=len-1)System.out.print(" ");}

		System.out.println();
		System.out.println(cnt);
	}

	public static void main(String[] args){

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		BubbleSort(box);

		scan.close();

	}

} public class Main{


	public static void BubbleSort(int[] array){
		int len=array.length;
		int cnt=0;
		int swap;
		for(int i=0;i<len-1;i++){
			for(int j=len-1;i<j;j--){
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			}
		}
		for(int i=0;i<len;i++){
		System.out.print(array[i]);
		if(i!=len-1)System.out.print(" ");}

		System.out.println();
		System.out.println(cnt);
	}

	public static void main(String[] args){

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		BubbleSort(box);

		scan.close();

	}

} Main
import java.util.Scanner;

public class Main{


	public static void BubbleSort(int[] array){
		int len=array.length;
		int cnt=0;
		int swap;
		for(int i=0;i<len-1;i++){
			for(int j=len-1;i<j;j--){
				if(array[j]<array[j-1]){
					cnt++;
					swap=array[j];array[j]=array[j-1];array[j-1]=swap;
				}
			}
		}
		for(int i=0;i<len;i++){
		System.out.print(array[i]);
		if(i!=len-1)System.out.print(" ");}

		System.out.println();
		System.out.println(cnt);
	}

	public static void main(String[] args){

		int n;

		Scanner scan=new Scanner(System.in);
		n=scan.nextInt();
		int[] box=new int[n];

		for(int i=0;i<n;i++){
		box[i]=scan.nextInt();
		}

		BubbleSort(box);

		scan.close();

	}

}