import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n,p,q=0;
        n=scan.nextInt();
        int[] sort=new int[n];
        for(int i=0; i<n; i++){
            sort[i]=scan.nextInt();
        }
        
        for(int i=0; i<n-1; i++){
            for(int j=0; j<n-1; j++){
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            }
        }
        //System.out.println(Arrays.toString(sort));
        for(int i=0; i<n; i++){
            System.out.print(sort[i]);
            if(i!=n-1)
                System.out.print(" ");
        }
        System.out.println();
        System.out.println(q);
    }
} import java.util.*; util.* java public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n,p,q=0;
        n=scan.nextInt();
        int[] sort=new int[n];
        for(int i=0; i<n; i++){
            sort[i]=scan.nextInt();
        }
        
        for(int i=0; i<n-1; i++){
            for(int j=0; j<n-1; j++){
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            }
        }
        //System.out.println(Arrays.toString(sort));
        for(int i=0; i<n; i++){
            System.out.print(sort[i]);
            if(i!=n-1)
                System.out.print(" ");
        }
        System.out.println();
        System.out.println(q);
    }
} Main public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n,p,q=0;
        n=scan.nextInt();
        int[] sort=new int[n];
        for(int i=0; i<n; i++){
            sort[i]=scan.nextInt();
        }
        
        for(int i=0; i<n-1; i++){
            for(int j=0; j<n-1; j++){
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            }
        }
        //System.out.println(Arrays.toString(sort));
        for(int i=0; i<n; i++){
            System.out.print(sort[i]);
            if(i!=n-1)
                System.out.print(" ");
        }
        System.out.println();
        System.out.println(q);
    } main {
        Scanner scan=new Scanner(System.in);
        int n,p,q=0;
        n=scan.nextInt();
        int[] sort=new int[n];
        for(int i=0; i<n; i++){
            sort[i]=scan.nextInt();
        }
        
        for(int i=0; i<n-1; i++){
            for(int j=0; j<n-1; j++){
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            }
        }
        //System.out.println(Arrays.toString(sort));
        for(int i=0; i<n; i++){
            System.out.print(sort[i]);
            if(i!=n-1)
                System.out.print(" ");
        }
        System.out.println();
        System.out.println(q);
    } Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int n n p p q=0; q 0 n=scan.nextInt() n scan.nextInt() scan.nextInt scan int[] sort=new int[n]; sort new int[n] n for(int i=0; i<n; i++){
            sort[i]=scan.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            sort[i]=scan.nextInt();
        } {
            sort[i]=scan.nextInt();
        } sort[i]=scan.nextInt() sort[i] sort i scan.nextInt() scan.nextInt scan for(int i=0; i<n-1; i++){
            for(int j=0; j<n-1; j++){
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            }
        } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 i++ i++ i {
            for(int j=0; j<n-1; j++){
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            }
        } {
            for(int j=0; j<n-1; j++){
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            }
        } for(int j=0; j<n-1; j++){
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            } int j=0; int j=0; j 0 j<n-1 j n-1 n 1 j++ j++ j {
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            } {
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            } if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                } sort[j]>sort[j+1] sort[j] sort j sort[j+1] sort j+1 j 1 {
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                } sort[j]^=sort[j+1] sort[j] sort j sort[j+1] sort j+1 j 1 sort[j+1]^=sort[j] sort[j+1] sort j+1 j 1 sort[j] sort j sort[j]^=sort[j+1] sort[j] sort j sort[j+1] sort j+1 j 1 q++ q for(int i=0; i<n; i++){
            System.out.print(sort[i]);
            if(i!=n-1)
                System.out.print(" ");
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            System.out.print(sort[i]);
            if(i!=n-1)
                System.out.print(" ");
        } {
            System.out.print(sort[i]);
            if(i!=n-1)
                System.out.print(" ");
        } System.out.print(sort[i]) System.out.print System.out System System.out sort[i] sort i if(i!=n-1)
                System.out.print(" "); i!=n-1 i n-1 n 1 System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out System.out.println(q) System.out.println System.out System System.out q String[] args args public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n,p,q=0;
        n=scan.nextInt();
        int[] sort=new int[n];
        for(int i=0; i<n; i++){
            sort[i]=scan.nextInt();
        }
        
        for(int i=0; i<n-1; i++){
            for(int j=0; j<n-1; j++){
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            }
        }
        //System.out.println(Arrays.toString(sort));
        for(int i=0; i<n; i++){
            System.out.print(sort[i]);
            if(i!=n-1)
                System.out.print(" ");
        }
        System.out.println();
        System.out.println(q);
    }
} public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n,p,q=0;
        n=scan.nextInt();
        int[] sort=new int[n];
        for(int i=0; i<n; i++){
            sort[i]=scan.nextInt();
        }
        
        for(int i=0; i<n-1; i++){
            for(int j=0; j<n-1; j++){
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            }
        }
        //System.out.println(Arrays.toString(sort));
        for(int i=0; i<n; i++){
            System.out.print(sort[i]);
            if(i!=n-1)
                System.out.print(" ");
        }
        System.out.println();
        System.out.println(q);
    }
} Main
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner scan=new Scanner(System.in);
        int n,p,q=0;
        n=scan.nextInt();
        int[] sort=new int[n];
        for(int i=0; i<n; i++){
            sort[i]=scan.nextInt();
        }
        
        for(int i=0; i<n-1; i++){
            for(int j=0; j<n-1; j++){
                if(sort[j]>sort[j+1]){
                    sort[j]^=sort[j+1];
                    sort[j+1]^=sort[j];
                    sort[j]^=sort[j+1];
                    q++;
                }
            }
        }
        //System.out.println(Arrays.toString(sort));
        for(int i=0; i<n; i++){
            System.out.print(sort[i]);
            if(i!=n-1)
                System.out.print(" ");
        }
        System.out.println();
        System.out.println(q);
    }
}
