import java.util.Scanner;

class Main{
    public static void main(String[] args){
	int i;
	int j;
	int v;
	int flag = 1;
	int count = 0;
	
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int A[] = new int[n];

	//Initialize data
	for(i=0 ; i<A.length ; i++){
	    int num = scan.nextInt();
	    A[i] = num;
	}
	
	while( flag==1 ){
	    flag = 0;
	    for(j=n-1 ; j>0 ; j--){
		if(A[j] < A[j-1]){
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		}
	    }
	}
	
	for(i=0 ; i<A.length-1 ; i++){
	    System.out.print(A[i]+" ");
	    }
	System.out.println(A[i]);
	System.out.println(count);
    }
    
}
 import java.util.Scanner; Scanner java.util class Main{
    public static void main(String[] args){
	int i;
	int j;
	int v;
	int flag = 1;
	int count = 0;
	
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int A[] = new int[n];

	//Initialize data
	for(i=0 ; i<A.length ; i++){
	    int num = scan.nextInt();
	    A[i] = num;
	}
	
	while( flag==1 ){
	    flag = 0;
	    for(j=n-1 ; j>0 ; j--){
		if(A[j] < A[j-1]){
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		}
	    }
	}
	
	for(i=0 ; i<A.length-1 ; i++){
	    System.out.print(A[i]+" ");
	    }
	System.out.println(A[i]);
	System.out.println(count);
    }
    
} Main public static void main(String[] args){
	int i;
	int j;
	int v;
	int flag = 1;
	int count = 0;
	
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int A[] = new int[n];

	//Initialize data
	for(i=0 ; i<A.length ; i++){
	    int num = scan.nextInt();
	    A[i] = num;
	}
	
	while( flag==1 ){
	    flag = 0;
	    for(j=n-1 ; j>0 ; j--){
		if(A[j] < A[j-1]){
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		}
	    }
	}
	
	for(i=0 ; i<A.length-1 ; i++){
	    System.out.print(A[i]+" ");
	    }
	System.out.println(A[i]);
	System.out.println(count);
    } main {
	int i;
	int j;
	int v;
	int flag = 1;
	int count = 0;
	
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int A[] = new int[n];

	//Initialize data
	for(i=0 ; i<A.length ; i++){
	    int num = scan.nextInt();
	    A[i] = num;
	}
	
	while( flag==1 ){
	    flag = 0;
	    for(j=n-1 ; j>0 ; j--){
		if(A[j] < A[j-1]){
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		}
	    }
	}
	
	for(i=0 ; i<A.length-1 ; i++){
	    System.out.print(A[i]+" ");
	    }
	System.out.println(A[i]);
	System.out.println(count);
    } int i; i int j; j int v; v int flag = 1; flag 1 int count = 0; count 0 Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int A[] = new int[n]; A new int[n] n for(i=0 ; i<A.length ; i++){
	    int num = scan.nextInt();
	    A[i] = num;
	} i=0 ; i=0 i 0 i<A.length i A.length A A.length i++ i++ i {
	    int num = scan.nextInt();
	    A[i] = num;
	} {
	    int num = scan.nextInt();
	    A[i] = num;
	} int num = scan.nextInt(); num scan.nextInt() scan.nextInt scan A[i] = num A[i] A i num while( flag==1 ){
	    flag = 0;
	    for(j=n-1 ; j>0 ; j--){
		if(A[j] < A[j-1]){
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		}
	    }
	} flag==1 flag 1 {
	    flag = 0;
	    for(j=n-1 ; j>0 ; j--){
		if(A[j] < A[j-1]){
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		}
	    }
	} flag = 0 flag 0 for(j=n-1 ; j>0 ; j--){
		if(A[j] < A[j-1]){
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		}
	    } j=n-1 ; j=n-1 j n-1 n 1 j>0 j 0 j-- j-- j {
		if(A[j] < A[j-1]){
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		}
	    } {
		if(A[j] < A[j-1]){
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		}
	    } if(A[j] < A[j-1]){
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		} A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 {
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		} v = A[j] v A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = v A[j-1] A j-1 j 1 v count++ count flag = 1 flag 1 for(i=0 ; i<A.length-1 ; i++){
	    System.out.print(A[i]+" ");
	    } i=0 ; i=0 i 0 i<A.length-1 i A.length-1 A.length A A.length 1 i++ i++ i {
	    System.out.print(A[i]+" ");
	    } {
	    System.out.print(A[i]+" ");
	    } System.out.print(A[i]+" ") System.out.print System.out System System.out A[i]+" " A[i] A i " " System.out.println(A[i]) System.out.println System.out System System.out A[i] A i System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.Scanner;

class Main{
    public static void main(String[] args){
	int i;
	int j;
	int v;
	int flag = 1;
	int count = 0;
	
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	int A[] = new int[n];

	//Initialize data
	for(i=0 ; i<A.length ; i++){
	    int num = scan.nextInt();
	    A[i] = num;
	}
	
	while( flag==1 ){
	    flag = 0;
	    for(j=n-1 ; j>0 ; j--){
		if(A[j] < A[j-1]){
		    v = A[j];
		    A[j] = A[j-1];
		    A[j-1] = v;
		    count++;
		    flag = 1;
		}
	    }
	}
	
	for(i=0 ; i<A.length-1 ; i++){
	    System.out.print(A[i]+" ");
	    }
	System.out.println(A[i]);
	System.out.println(count);
    }
    
}

