import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);    
        int N=0;
        N = sc.nextInt();
        int[] A;
        A = new int[N];
        int i=0;
        for(i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int j;
        int k;
        int z;
        int swap = 0;
        for(j=0;j<N-1;j++){
            for(k=0;k<N-1;k++){
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            }
        }

        for(i=0;i<N-1;i++){
            System.out.print(A[i]+" ");
        }
        System.out.println(A[N-1]);
        System.out.println(swap);   
        sc.close();
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);    
        int N=0;
        N = sc.nextInt();
        int[] A;
        A = new int[N];
        int i=0;
        for(i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int j;
        int k;
        int z;
        int swap = 0;
        for(j=0;j<N-1;j++){
            for(k=0;k<N-1;k++){
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            }
        }

        for(i=0;i<N-1;i++){
            System.out.print(A[i]+" ");
        }
        System.out.println(A[N-1]);
        System.out.println(swap);   
        sc.close();
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);    
        int N=0;
        N = sc.nextInt();
        int[] A;
        A = new int[N];
        int i=0;
        for(i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int j;
        int k;
        int z;
        int swap = 0;
        for(j=0;j<N-1;j++){
            for(k=0;k<N-1;k++){
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            }
        }

        for(i=0;i<N-1;i++){
            System.out.print(A[i]+" ");
        }
        System.out.println(A[N-1]);
        System.out.println(swap);   
        sc.close();
    } main {
        Scanner sc = new Scanner(System.in);    
        int N=0;
        N = sc.nextInt();
        int[] A;
        A = new int[N];
        int i=0;
        for(i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int j;
        int k;
        int z;
        int swap = 0;
        for(j=0;j<N-1;j++){
            for(k=0;k<N-1;k++){
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            }
        }

        for(i=0;i<N-1;i++){
            System.out.print(A[i]+" ");
        }
        System.out.println(A[N-1]);
        System.out.println(swap);   
        sc.close();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int N=0; N 0 N = sc.nextInt() N sc.nextInt() sc.nextInt sc int[] A; A A = new int[N] A new int[N] N int i=0; i 0 for(i=0;i<N;i++){
            A[i] = sc.nextInt();
        } i=0; i=0 i 0 i<N i N i++ i++ i {
            A[i] = sc.nextInt();
        } {
            A[i] = sc.nextInt();
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int j; j int k; k int z; z int swap = 0; swap 0 for(j=0;j<N-1;j++){
            for(k=0;k<N-1;k++){
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            }
        } j=0; j=0 j 0 j<N-1 j N-1 N 1 j++ j++ j {
            for(k=0;k<N-1;k++){
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            }
        } {
            for(k=0;k<N-1;k++){
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            }
        } for(k=0;k<N-1;k++){
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            } k=0; k=0 k 0 k<N-1 k N-1 N 1 k++ k++ k {
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            } {
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            } if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                } A[k]>A[k+1] A[k] A k A[k+1] A k+1 k 1 {
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                } z = A[k] z A[k] A k A[k] = A[k+1] A[k] A k A[k+1] A k+1 k 1 A[k+1] = z A[k+1] A k+1 k 1 z swap++ swap for(i=0;i<N-1;i++){
            System.out.print(A[i]+" ");
        } i=0; i=0 i 0 i<N-1 i N-1 N 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[N-1]) System.out.println System.out System System.out A[N-1] A N-1 N 1 System.out.println(swap) System.out.println System.out System System.out swap sc.close() sc.close sc String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);    
        int N=0;
        N = sc.nextInt();
        int[] A;
        A = new int[N];
        int i=0;
        for(i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int j;
        int k;
        int z;
        int swap = 0;
        for(j=0;j<N-1;j++){
            for(k=0;k<N-1;k++){
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            }
        }

        for(i=0;i<N-1;i++){
            System.out.print(A[i]+" ");
        }
        System.out.println(A[N-1]);
        System.out.println(swap);   
        sc.close();
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);    
        int N=0;
        N = sc.nextInt();
        int[] A;
        A = new int[N];
        int i=0;
        for(i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int j;
        int k;
        int z;
        int swap = 0;
        for(j=0;j<N-1;j++){
            for(k=0;k<N-1;k++){
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            }
        }

        for(i=0;i<N-1;i++){
            System.out.print(A[i]+" ");
        }
        System.out.println(A[N-1]);
        System.out.println(swap);   
        sc.close();
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);    
        int N=0;
        N = sc.nextInt();
        int[] A;
        A = new int[N];
        int i=0;
        for(i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int j;
        int k;
        int z;
        int swap = 0;
        for(j=0;j<N-1;j++){
            for(k=0;k<N-1;k++){
                if(A[k]>A[k+1]){
                    z = A[k];
                    A[k] = A[k+1];
                    A[k+1] = z;
                    swap++;
                }
            }
        }

        for(i=0;i<N-1;i++){
            System.out.print(A[i]+" ");
        }
        System.out.println(A[N-1]);
        System.out.println(swap);   
        sc.close();
    }
}
