import java.util.Scanner;

public class Main{
    public static void main(String[] args){

	//配列の要素数
	Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

	//配列の要素
	int A[] = new int[n];	
	for(int i=0;i<A.length;i++){
	    A[i]= scanner.nextInt();
	}
	bubbleSort(A,n);
    }
    //並べ替え
    private static void bubbleSort(int A[],int N){
	int flag = 1;
	int count = 0;

	while(flag != 0){
	    flag = 0;
	    for(int j=N-1; j > 0; j--){
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    }
	}
	Print(A,N);
	System.out.println(count);
    }
    //表示
    private static void Print(int A[], int n){
	for(int k=0;k<A.length;k++){
	    System.out.print(A[k]);
	    if(k < (n-1)){
		System.out.print(" ");
	    }
	}
	System.out.println();
    }
}

 import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){

	//配列の要素数
	Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

	//配列の要素
	int A[] = new int[n];	
	for(int i=0;i<A.length;i++){
	    A[i]= scanner.nextInt();
	}
	bubbleSort(A,n);
    }
    //並べ替え
    private static void bubbleSort(int A[],int N){
	int flag = 1;
	int count = 0;

	while(flag != 0){
	    flag = 0;
	    for(int j=N-1; j > 0; j--){
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    }
	}
	Print(A,N);
	System.out.println(count);
    }
    //表示
    private static void Print(int A[], int n){
	for(int k=0;k<A.length;k++){
	    System.out.print(A[k]);
	    if(k < (n-1)){
		System.out.print(" ");
	    }
	}
	System.out.println();
    }
} Main public static void main(String[] args){

	//配列の要素数
	Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

	//配列の要素
	int A[] = new int[n];	
	for(int i=0;i<A.length;i++){
	    A[i]= scanner.nextInt();
	}
	bubbleSort(A,n);
    } main {

	//配列の要素数
	Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

	//配列の要素
	int A[] = new int[n];	
	for(int i=0;i<A.length;i++){
	    A[i]= scanner.nextInt();
	}
	bubbleSort(A,n);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int n = scanner.nextInt(); n scanner.nextInt() scanner.nextInt scanner int A[] = new int[n]; A new int[n] n for(int i=0;i<A.length;i++){
	    A[i]= scanner.nextInt();
	} int i=0; int i=0; i 0 i<A.length i A.length A A.length i++ i++ i {
	    A[i]= scanner.nextInt();
	} {
	    A[i]= scanner.nextInt();
	} A[i]= scanner.nextInt() A[i] A i scanner.nextInt() scanner.nextInt scanner bubbleSort(A,n) bubbleSort A n String[] args args //並べ替え
    private static void bubbleSort(int A[],int N){
	int flag = 1;
	int count = 0;

	while(flag != 0){
	    flag = 0;
	    for(int j=N-1; j > 0; j--){
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    }
	}
	Print(A,N);
	System.out.println(count);
    } bubbleSort {
	int flag = 1;
	int count = 0;

	while(flag != 0){
	    flag = 0;
	    for(int j=N-1; j > 0; j--){
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    }
	}
	Print(A,N);
	System.out.println(count);
    } int flag = 1; flag 1 int count = 0; count 0 while(flag != 0){
	    flag = 0;
	    for(int j=N-1; j > 0; j--){
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    }
	} flag != 0 flag 0 {
	    flag = 0;
	    for(int j=N-1; j > 0; j--){
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    }
	} flag = 0 flag 0 for(int j=N-1; j > 0; j--){
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    } int j=N-1; int j=N-1; j N-1 N 1 j > 0 j 0 j-- j-- j {
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    } {
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    } if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		} A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 {
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		} int v = A[j]; v A[j] A j int w = A[j-1]; w A[j-1] A j-1 j 1 A[j] = w A[j] A j w A[j-1] = v A[j-1] A j-1 j 1 v flag = 1 flag 1 count++ count Print(A,N) Print A N System.out.println(count) System.out.println System.out System System.out count int A[] A int N N //表示
    private static void Print(int A[], int n){
	for(int k=0;k<A.length;k++){
	    System.out.print(A[k]);
	    if(k < (n-1)){
		System.out.print(" ");
	    }
	}
	System.out.println();
    } Print {
	for(int k=0;k<A.length;k++){
	    System.out.print(A[k]);
	    if(k < (n-1)){
		System.out.print(" ");
	    }
	}
	System.out.println();
    } for(int k=0;k<A.length;k++){
	    System.out.print(A[k]);
	    if(k < (n-1)){
		System.out.print(" ");
	    }
	} int k=0; int k=0; k 0 k<A.length k A.length A A.length k++ k++ k {
	    System.out.print(A[k]);
	    if(k < (n-1)){
		System.out.print(" ");
	    }
	} {
	    System.out.print(A[k]);
	    if(k < (n-1)){
		System.out.print(" ");
	    }
	} System.out.print(A[k]) System.out.print System.out System System.out A[k] A k if(k < (n-1)){
		System.out.print(" ");
	    } k < (n-1) k (n-1) n 1 {
		System.out.print(" ");
	    } System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out int A[] A int n n public class Main{
    public static void main(String[] args){

	//配列の要素数
	Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

	//配列の要素
	int A[] = new int[n];	
	for(int i=0;i<A.length;i++){
	    A[i]= scanner.nextInt();
	}
	bubbleSort(A,n);
    }
    //並べ替え
    private static void bubbleSort(int A[],int N){
	int flag = 1;
	int count = 0;

	while(flag != 0){
	    flag = 0;
	    for(int j=N-1; j > 0; j--){
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    }
	}
	Print(A,N);
	System.out.println(count);
    }
    //表示
    private static void Print(int A[], int n){
	for(int k=0;k<A.length;k++){
	    System.out.print(A[k]);
	    if(k < (n-1)){
		System.out.print(" ");
	    }
	}
	System.out.println();
    }
} public class Main{
    public static void main(String[] args){

	//配列の要素数
	Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

	//配列の要素
	int A[] = new int[n];	
	for(int i=0;i<A.length;i++){
	    A[i]= scanner.nextInt();
	}
	bubbleSort(A,n);
    }
    //並べ替え
    private static void bubbleSort(int A[],int N){
	int flag = 1;
	int count = 0;

	while(flag != 0){
	    flag = 0;
	    for(int j=N-1; j > 0; j--){
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    }
	}
	Print(A,N);
	System.out.println(count);
    }
    //表示
    private static void Print(int A[], int n){
	for(int k=0;k<A.length;k++){
	    System.out.print(A[k]);
	    if(k < (n-1)){
		System.out.print(" ");
	    }
	}
	System.out.println();
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){

	//配列の要素数
	Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

	//配列の要素
	int A[] = new int[n];	
	for(int i=0;i<A.length;i++){
	    A[i]= scanner.nextInt();
	}
	bubbleSort(A,n);
    }
    //並べ替え
    private static void bubbleSort(int A[],int N){
	int flag = 1;
	int count = 0;

	while(flag != 0){
	    flag = 0;
	    for(int j=N-1; j > 0; j--){
		if(A[j] < A[j-1]){
		    int v = A[j];
		    int w = A[j-1];
		    A[j] = w;
		    A[j-1] = v;
		    flag = 1;
		    count++;
		}	
	    }
	}
	Print(A,N);
	System.out.println(count);
    }
    //表示
    private static void Print(int A[], int n){
	for(int k=0;k<A.length;k++){
	    System.out.print(A[k]);
	    if(k < (n-1)){
		System.out.print(" ");
	    }
	}
	System.out.println();
    }
}


