import java.util.Scanner;
class Main{
    
    static int[] A;

    public static void main(String[] args){
	int i = 0;
	Main bubble = new Main();
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	A = new int[n];
	
	while(i<n){
	    A[i++] = scan.nextInt();
	    //	    i++;
	}
	int count = 0;
	count = bubble.bubblesort(A);
	bubble.call(n);
	System.out.println(count);
    }
    


    public int bubblesort(int[] A){
	int count =0;
	for(int i = 0;i<A.length ;i++){

	    for(int j = A.length-1;j >=i+1;j--){
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    }
	}
	return count;
	
    }

    public void swap(int x,int y){
	int m = 0;
	int n = 0;
	m = A[x];
	n = A[y];
	A[x] = n;
	A[y] = m;

    }

    public void call(int n){
	int i =0;
	while(true){
	    if(i!=0) System.out.print(" ");
	    System.out.print(A[i]);
	    i++;
	    if(i==n)break;
	}
	System.out.println();
    }
    

} import java.util.Scanner; Scanner java.util class Main{
    
    static int[] A;

    public static void main(String[] args){
	int i = 0;
	Main bubble = new Main();
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	A = new int[n];
	
	while(i<n){
	    A[i++] = scan.nextInt();
	    //	    i++;
	}
	int count = 0;
	count = bubble.bubblesort(A);
	bubble.call(n);
	System.out.println(count);
    }
    


    public int bubblesort(int[] A){
	int count =0;
	for(int i = 0;i<A.length ;i++){

	    for(int j = A.length-1;j >=i+1;j--){
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    }
	}
	return count;
	
    }

    public void swap(int x,int y){
	int m = 0;
	int n = 0;
	m = A[x];
	n = A[y];
	A[x] = n;
	A[y] = m;

    }

    public void call(int n){
	int i =0;
	while(true){
	    if(i!=0) System.out.print(" ");
	    System.out.print(A[i]);
	    i++;
	    if(i==n)break;
	}
	System.out.println();
    }
    

} Main static int[] A; A public static void main(String[] args){
	int i = 0;
	Main bubble = new Main();
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	A = new int[n];
	
	while(i<n){
	    A[i++] = scan.nextInt();
	    //	    i++;
	}
	int count = 0;
	count = bubble.bubblesort(A);
	bubble.call(n);
	System.out.println(count);
    } main {
	int i = 0;
	Main bubble = new Main();
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	A = new int[n];
	
	while(i<n){
	    A[i++] = scan.nextInt();
	    //	    i++;
	}
	int count = 0;
	count = bubble.bubblesort(A);
	bubble.call(n);
	System.out.println(count);
    } int i = 0; i 0 Main bubble = new Main(); bubble new Main() Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan A = new int[n] A new int[n] n while(i<n){
	    A[i++] = scan.nextInt();
	    //	    i++;
	} i<n i n {
	    A[i++] = scan.nextInt();
	    //	    i++;
	} A[i++] = scan.nextInt() A[i++] A i++ i scan.nextInt() scan.nextInt scan int count = 0; count 0 count = bubble.bubblesort(A) count bubble.bubblesort(A) bubble.bubblesort bubble A bubble.call(n) bubble.call bubble n System.out.println(count) System.out.println System.out System System.out count String[] args args public int bubblesort(int[] A){
	int count =0;
	for(int i = 0;i<A.length ;i++){

	    for(int j = A.length-1;j >=i+1;j--){
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    }
	}
	return count;
	
    } bubblesort {
	int count =0;
	for(int i = 0;i<A.length ;i++){

	    for(int j = A.length-1;j >=i+1;j--){
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    }
	}
	return count;
	
    } int count =0; count 0 for(int i = 0;i<A.length ;i++){

	    for(int j = A.length-1;j >=i+1;j--){
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    }
	} int i = 0; int i = 0; i 0 i<A.length i A.length A A.length i++ i++ i {

	    for(int j = A.length-1;j >=i+1;j--){
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    }
	} {

	    for(int j = A.length-1;j >=i+1;j--){
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    }
	} for(int j = A.length-1;j >=i+1;j--){
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    } int j = A.length-1; int j = A.length-1; j A.length-1 A.length A A.length 1 j >=i+1 j i+1 i 1 j-- j-- j {
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    } {
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    } if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		} A[j]<A[j-1] A[j] A j A[j-1] A j-1 j 1 {
		    swap(j,j-1);
		    count++;
		} swap(j,j-1) swap j j-1 j 1 count++ count return count; count int[] A A public void swap(int x,int y){
	int m = 0;
	int n = 0;
	m = A[x];
	n = A[y];
	A[x] = n;
	A[y] = m;

    } swap {
	int m = 0;
	int n = 0;
	m = A[x];
	n = A[y];
	A[x] = n;
	A[y] = m;

    } int m = 0; m 0 int n = 0; n 0 m = A[x] m A[x] A x n = A[y] n A[y] A y A[x] = n A[x] A x n A[y] = m A[y] A y m int x x int y y public void call(int n){
	int i =0;
	while(true){
	    if(i!=0) System.out.print(" ");
	    System.out.print(A[i]);
	    i++;
	    if(i==n)break;
	}
	System.out.println();
    } call {
	int i =0;
	while(true){
	    if(i!=0) System.out.print(" ");
	    System.out.print(A[i]);
	    i++;
	    if(i==n)break;
	}
	System.out.println();
    } int i =0; i 0 while(true){
	    if(i!=0) System.out.print(" ");
	    System.out.print(A[i]);
	    i++;
	    if(i==n)break;
	} true {
	    if(i!=0) System.out.print(" ");
	    System.out.print(A[i]);
	    i++;
	    if(i==n)break;
	} if(i!=0) System.out.print(" "); i!=0 i 0 System.out.print(" ") System.out.print System.out System System.out " " System.out.print(A[i]) System.out.print System.out System System.out A[i] A i i++ i if(i==n)break; i==n i n break; System.out.println() System.out.println System.out System System.out int n n
import java.util.Scanner;
class Main{
    
    static int[] A;

    public static void main(String[] args){
	int i = 0;
	Main bubble = new Main();
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	A = new int[n];
	
	while(i<n){
	    A[i++] = scan.nextInt();
	    //	    i++;
	}
	int count = 0;
	count = bubble.bubblesort(A);
	bubble.call(n);
	System.out.println(count);
    }
    


    public int bubblesort(int[] A){
	int count =0;
	for(int i = 0;i<A.length ;i++){

	    for(int j = A.length-1;j >=i+1;j--){
		if(A[j]<A[j-1]){
		    swap(j,j-1);
		    count++;
		}
	    }
	}
	return count;
	
    }

    public void swap(int x,int y){
	int m = 0;
	int n = 0;
	m = A[x];
	n = A[y];
	A[x] = n;
	A[y] = m;

    }

    public void call(int n){
	int i =0;
	while(true){
	    if(i!=0) System.out.print(" ");
	    System.out.print(A[i]);
	    i++;
	    if(i==n)break;
	}
	System.out.println();
    }
    

}