import java.util.*;
class Main{
	Scanner sc=new Scanner(System.in);
	int[] su=new int[100];
	int sum;
	void go(){
		int n=sc.nextInt();
		
		for(int i=0; i<n; i++){
			su[i]=sc.nextInt();
		}
		for(int i=n-1; i>0; i--){
			for(int j=0; j<i; j++){
				if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				}
			}
		}
		for(int i=0; i<n; i++){
			if(i<n-1){
				System.out.print(su[i]+" ");
			}else{
				System.out.println(su[i]);
			}
		}
		System.out.println(sum);
	}
	public static void main(String[]agrs){
		new Main().go();
	}
} import java.util.*; util.* java class Main{
	Scanner sc=new Scanner(System.in);
	int[] su=new int[100];
	int sum;
	void go(){
		int n=sc.nextInt();
		
		for(int i=0; i<n; i++){
			su[i]=sc.nextInt();
		}
		for(int i=n-1; i>0; i--){
			for(int j=0; j<i; j++){
				if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				}
			}
		}
		for(int i=0; i<n; i++){
			if(i<n-1){
				System.out.print(su[i]+" ");
			}else{
				System.out.println(su[i]);
			}
		}
		System.out.println(sum);
	}
	public static void main(String[]agrs){
		new Main().go();
	}
} Main Scanner sc=new Scanner(System.in); sc new Scanner(System.in) int[] su=new int[100]; su new int[100] 100 int sum; sum void go(){
		int n=sc.nextInt();
		
		for(int i=0; i<n; i++){
			su[i]=sc.nextInt();
		}
		for(int i=n-1; i>0; i--){
			for(int j=0; j<i; j++){
				if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				}
			}
		}
		for(int i=0; i<n; i++){
			if(i<n-1){
				System.out.print(su[i]+" ");
			}else{
				System.out.println(su[i]);
			}
		}
		System.out.println(sum);
	} go {
		int n=sc.nextInt();
		
		for(int i=0; i<n; i++){
			su[i]=sc.nextInt();
		}
		for(int i=n-1; i>0; i--){
			for(int j=0; j<i; j++){
				if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				}
			}
		}
		for(int i=0; i<n; i++){
			if(i<n-1){
				System.out.print(su[i]+" ");
			}else{
				System.out.println(su[i]);
			}
		}
		System.out.println(sum);
	} int n=sc.nextInt(); n sc.nextInt() sc.nextInt sc for(int i=0; i<n; i++){
			su[i]=sc.nextInt();
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			su[i]=sc.nextInt();
		} {
			su[i]=sc.nextInt();
		} su[i]=sc.nextInt() su[i] su i sc.nextInt() sc.nextInt sc for(int i=n-1; i>0; i--){
			for(int j=0; j<i; j++){
				if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				}
			}
		} int i=n-1; int i=n-1; i n-1 n 1 i>0 i 0 i-- i-- i {
			for(int j=0; j<i; j++){
				if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				}
			}
		} {
			for(int j=0; j<i; j++){
				if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				}
			}
		} for(int j=0; j<i; j++){
				if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				}
			} int j=0; int j=0; j 0 j<i j i j++ j++ j {
				if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				}
			} {
				if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				}
			} if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				} su[j]>su[j+1] su[j] su j su[j+1] su j+1 j 1 {
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				} sum++ sum int a=su[j+1]; a su[j+1] su j+1 j 1 su[j+1]=su[j] su[j+1] su j+1 j 1 su[j] su j su[j]=a su[j] su j a for(int i=0; i<n; i++){
			if(i<n-1){
				System.out.print(su[i]+" ");
			}else{
				System.out.println(su[i]);
			}
		} int i=0; int i=0; i 0 i<n i n i++ i++ i {
			if(i<n-1){
				System.out.print(su[i]+" ");
			}else{
				System.out.println(su[i]);
			}
		} {
			if(i<n-1){
				System.out.print(su[i]+" ");
			}else{
				System.out.println(su[i]);
			}
		} if(i<n-1){
				System.out.print(su[i]+" ");
			}else{
				System.out.println(su[i]);
			} i<n-1 i n-1 n 1 {
				System.out.print(su[i]+" ");
			} System.out.print(su[i]+" ") System.out.print System.out System System.out su[i]+" " su[i] su i " " {
				System.out.println(su[i]);
			} System.out.println(su[i]) System.out.println System.out System System.out su[i] su i System.out.println(sum) System.out.println System.out System System.out sum public static void main(String[]agrs){
		new Main().go();
	} main {
		new Main().go();
	} new Main().go() new Main().go new Main() String[]agrs agrs
import java.util.*;
class Main{
	Scanner sc=new Scanner(System.in);
	int[] su=new int[100];
	int sum;
	void go(){
		int n=sc.nextInt();
		
		for(int i=0; i<n; i++){
			su[i]=sc.nextInt();
		}
		for(int i=n-1; i>0; i--){
			for(int j=0; j<i; j++){
				if(su[j]>su[j+1]){
					sum++;
					int a=su[j+1];
					su[j+1]=su[j];
	  			  	su[j]=a;
				}
			}
		}
		for(int i=0; i<n; i++){
			if(i<n-1){
				System.out.print(su[i]+" ");
			}else{
				System.out.println(su[i]);
			}
		}
		System.out.println(sum);
	}
	public static void main(String[]agrs){
		new Main().go();
	}
}