import java.util.Scanner;
public class Main{    
    public static void trace ( int n,int []A){
        for ( int j = 0; j < n; j++){
            if ( j > 0 ) System.out.print(" ");
            System.out.print(A[j]);
        }
            System.out.print("\n");
    }
                             
                            
     public static void main(String[] args){
        int n;
        int[] A;
                    
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        A = new int[n];
        
        for ( int j = 0; j < n; j++ ) A[j] = sc.nextInt();
         //bubble sort
        int k=0;
        int tmp=0;
        boolean flag = true;
        while (flag){
            flag = false;
            for ( int j = n-1;j > 0; j--){
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            }
        }
         trace(n,A);
         System.out.println(k);
    }
} import java.util.Scanner; Scanner java.util public class Main{    
    public static void trace ( int n,int []A){
        for ( int j = 0; j < n; j++){
            if ( j > 0 ) System.out.print(" ");
            System.out.print(A[j]);
        }
            System.out.print("\n");
    }
                             
                            
     public static void main(String[] args){
        int n;
        int[] A;
                    
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        A = new int[n];
        
        for ( int j = 0; j < n; j++ ) A[j] = sc.nextInt();
         //bubble sort
        int k=0;
        int tmp=0;
        boolean flag = true;
        while (flag){
            flag = false;
            for ( int j = n-1;j > 0; j--){
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            }
        }
         trace(n,A);
         System.out.println(k);
    }
} Main public static void trace ( int n,int []A){
        for ( int j = 0; j < n; j++){
            if ( j > 0 ) System.out.print(" ");
            System.out.print(A[j]);
        }
            System.out.print("\n");
    } trace {
        for ( int j = 0; j < n; j++){
            if ( j > 0 ) System.out.print(" ");
            System.out.print(A[j]);
        }
            System.out.print("\n");
    } for ( int j = 0; j < n; j++){
            if ( j > 0 ) System.out.print(" ");
            System.out.print(A[j]);
        } int j = 0; int j = 0; j 0 j < n j n j++ j++ j {
            if ( j > 0 ) System.out.print(" ");
            System.out.print(A[j]);
        } {
            if ( j > 0 ) System.out.print(" ");
            System.out.print(A[j]);
        } if ( j > 0 ) System.out.print(" "); j > 0 j 0 System.out.print(" ") System.out.print System.out System System.out " " System.out.print(A[j]) System.out.print System.out System System.out A[j] A j System.out.print("\n") System.out.print System.out System System.out "\n" int n n int []A A public static void main(String[] args){
        int n;
        int[] A;
                    
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        A = new int[n];
        
        for ( int j = 0; j < n; j++ ) A[j] = sc.nextInt();
         //bubble sort
        int k=0;
        int tmp=0;
        boolean flag = true;
        while (flag){
            flag = false;
            for ( int j = n-1;j > 0; j--){
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            }
        }
         trace(n,A);
         System.out.println(k);
    } main {
        int n;
        int[] A;
                    
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        A = new int[n];
        
        for ( int j = 0; j < n; j++ ) A[j] = sc.nextInt();
         //bubble sort
        int k=0;
        int tmp=0;
        boolean flag = true;
        while (flag){
            flag = false;
            for ( int j = n-1;j > 0; j--){
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            }
        }
         trace(n,A);
         System.out.println(k);
    } int n; n int[] A; A Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc A = new int[n] A new int[n] n for ( int j = 0; j < n; j++ ) A[j] = sc.nextInt(); int j = 0; int j = 0; j 0 j < n j n j++ j++ j A[j] = sc.nextInt(); A[j] = sc.nextInt() A[j] A j sc.nextInt() sc.nextInt sc int k=0; k 0 int tmp=0; tmp 0 boolean flag = true; flag true while (flag){
            flag = false;
            for ( int j = n-1;j > 0; j--){
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            }
        } flag {
            flag = false;
            for ( int j = n-1;j > 0; j--){
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            }
        } flag = false flag false for ( int j = n-1;j > 0; j--){
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            } 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] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            } {
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            } if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                } A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                } tmp    = A[j-1] tmp A[j-1] A j-1 j 1 A[j-1] = A[j] A[j-1] A j-1 j 1 A[j] A j A[j]   = tmp A[j] A j tmp k++ k flag = true flag true trace(n,A) trace n A System.out.println(k) System.out.println System.out System System.out k String[] args args public class Main{    
    public static void trace ( int n,int []A){
        for ( int j = 0; j < n; j++){
            if ( j > 0 ) System.out.print(" ");
            System.out.print(A[j]);
        }
            System.out.print("\n");
    }
                             
                            
     public static void main(String[] args){
        int n;
        int[] A;
                    
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        A = new int[n];
        
        for ( int j = 0; j < n; j++ ) A[j] = sc.nextInt();
         //bubble sort
        int k=0;
        int tmp=0;
        boolean flag = true;
        while (flag){
            flag = false;
            for ( int j = n-1;j > 0; j--){
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            }
        }
         trace(n,A);
         System.out.println(k);
    }
} public class Main{    
    public static void trace ( int n,int []A){
        for ( int j = 0; j < n; j++){
            if ( j > 0 ) System.out.print(" ");
            System.out.print(A[j]);
        }
            System.out.print("\n");
    }
                             
                            
     public static void main(String[] args){
        int n;
        int[] A;
                    
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        A = new int[n];
        
        for ( int j = 0; j < n; j++ ) A[j] = sc.nextInt();
         //bubble sort
        int k=0;
        int tmp=0;
        boolean flag = true;
        while (flag){
            flag = false;
            for ( int j = n-1;j > 0; j--){
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            }
        }
         trace(n,A);
         System.out.println(k);
    }
} Main
import java.util.Scanner;
public class Main{    
    public static void trace ( int n,int []A){
        for ( int j = 0; j < n; j++){
            if ( j > 0 ) System.out.print(" ");
            System.out.print(A[j]);
        }
            System.out.print("\n");
    }
                             
                            
     public static void main(String[] args){
        int n;
        int[] A;
                    
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        A = new int[n];
        
        for ( int j = 0; j < n; j++ ) A[j] = sc.nextInt();
         //bubble sort
        int k=0;
        int tmp=0;
        boolean flag = true;
        while (flag){
            flag = false;
            for ( int j = n-1;j > 0; j--){
                if ( A[j] < A[j-1] ) {
                    tmp    = A[j-1];
                    A[j-1] = A[j];
                    A[j]   = tmp; 
                    k++;
                    flag = true;
                }
            }
        }
         trace(n,A);
         System.out.println(k);
    }
}