import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i,c,j,count=0,N;
        N=sc.nextInt();
        int[] array;
        array= new int[N];
        for(i=0;i<=N-1;i++){
            array[i]=sc.nextInt();
        }
        for(j=1;j<=N-1;j++){
            for(i=N-1;i>=j;i--){
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            }
        }
        for(i=0;i<N-1;i++){
            System.out.print(array[i]+" ");
        }
        System.out.println(array[N-1]+"\n"+count);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i,c,j,count=0,N;
        N=sc.nextInt();
        int[] array;
        array= new int[N];
        for(i=0;i<=N-1;i++){
            array[i]=sc.nextInt();
        }
        for(j=1;j<=N-1;j++){
            for(i=N-1;i>=j;i--){
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            }
        }
        for(i=0;i<N-1;i++){
            System.out.print(array[i]+" ");
        }
        System.out.println(array[N-1]+"\n"+count);
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i,c,j,count=0,N;
        N=sc.nextInt();
        int[] array;
        array= new int[N];
        for(i=0;i<=N-1;i++){
            array[i]=sc.nextInt();
        }
        for(j=1;j<=N-1;j++){
            for(i=N-1;i>=j;i--){
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            }
        }
        for(i=0;i<N-1;i++){
            System.out.print(array[i]+" ");
        }
        System.out.println(array[N-1]+"\n"+count);
    } main {
        Scanner sc = new Scanner(System.in);
        int i,c,j,count=0,N;
        N=sc.nextInt();
        int[] array;
        array= new int[N];
        for(i=0;i<=N-1;i++){
            array[i]=sc.nextInt();
        }
        for(j=1;j<=N-1;j++){
            for(i=N-1;i>=j;i--){
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            }
        }
        for(i=0;i<N-1;i++){
            System.out.print(array[i]+" ");
        }
        System.out.println(array[N-1]+"\n"+count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int i i c c j j count=0 count 0 N; N N=sc.nextInt() N sc.nextInt() sc.nextInt sc int[] array; array array= new int[N] array new int[N] N for(i=0;i<=N-1;i++){
            array[i]=sc.nextInt();
        } i=0; i=0 i 0 i<=N-1 i N-1 N 1 i++ i++ i {
            array[i]=sc.nextInt();
        } {
            array[i]=sc.nextInt();
        } array[i]=sc.nextInt() array[i] array i sc.nextInt() sc.nextInt sc for(j=1;j<=N-1;j++){
            for(i=N-1;i>=j;i--){
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            }
        } j=1; j=1 j 1 j<=N-1 j N-1 N 1 j++ j++ j {
            for(i=N-1;i>=j;i--){
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            }
        } {
            for(i=N-1;i>=j;i--){
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            }
        } for(i=N-1;i>=j;i--){
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            } i=N-1; i=N-1 i N-1 N 1 i>=j i j i-- i-- i {
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            } {
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            } if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                } array[i]<array[i-1] array[i] array i array[i-1] array i-1 i 1 {
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                } c=array[i] c array[i] array i array[i]=array[i-1] array[i] array i array[i-1] array i-1 i 1 array[i-1]=c array[i-1] array i-1 i 1 c count++ count {
                    continue;
                } continue; for(i=0;i<N-1;i++){
            System.out.print(array[i]+" ");
        } i=0; i=0 i 0 i<N-1 i N-1 N 1 i++ i++ i {
            System.out.print(array[i]+" ");
        } {
            System.out.print(array[i]+" ");
        } System.out.print(array[i]+" ") System.out.print System.out System System.out array[i]+" " array[i] array i " " System.out.println(array[N-1]+"\n"+count) System.out.println System.out System System.out array[N-1]+"\n"+count array[N-1]+"\n"+count array[N-1] array N-1 N 1 "\n" count String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i,c,j,count=0,N;
        N=sc.nextInt();
        int[] array;
        array= new int[N];
        for(i=0;i<=N-1;i++){
            array[i]=sc.nextInt();
        }
        for(j=1;j<=N-1;j++){
            for(i=N-1;i>=j;i--){
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            }
        }
        for(i=0;i<N-1;i++){
            System.out.print(array[i]+" ");
        }
        System.out.println(array[N-1]+"\n"+count);
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i,c,j,count=0,N;
        N=sc.nextInt();
        int[] array;
        array= new int[N];
        for(i=0;i<=N-1;i++){
            array[i]=sc.nextInt();
        }
        for(j=1;j<=N-1;j++){
            for(i=N-1;i>=j;i--){
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            }
        }
        for(i=0;i<N-1;i++){
            System.out.print(array[i]+" ");
        }
        System.out.println(array[N-1]+"\n"+count);
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i,c,j,count=0,N;
        N=sc.nextInt();
        int[] array;
        array= new int[N];
        for(i=0;i<=N-1;i++){
            array[i]=sc.nextInt();
        }
        for(j=1;j<=N-1;j++){
            for(i=N-1;i>=j;i--){
                if(array[i]<array[i-1]){
                    c=array[i];
                    array[i]=array[i-1];
                    array[i-1]=c;
                    count++;
                }else{
                    continue;
                }
            }
        }
        for(i=0;i<N-1;i++){
            System.out.print(array[i]+" ");
        }
        System.out.println(array[N-1]+"\n"+count);
    }
}
