import java.util.Scanner;

public class Main
{
    public static int N;
    public static int[] List=new int[100];
    public static int Count=0;
    public static int flag=0;


    public  static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        N=scan.nextInt();

        for(int k=0;k<N;k++)
        {
            List[k]=scan.nextInt();
        }

        for(int k=0;k<N;k++)
        {
            BubbleSort(k);
        }

        for(int n=0;n<N;n++)
        {
            if(n!=N-1)
                System.out.print(List[n]+" ");
            if(n==N-1)
                System.out.println(List[n]);
        }
        System.out.println(Count);

    }

    public static void BubbleSort(int j)
    {
            for(int k=N-1;k>=1;k--)
            {
                flag=0;
                if(List[k]<List[k-1])
                {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                }
                if(flag==1) Count++;
            }
    }
} import java.util.Scanner; Scanner java.util public class Main
{
    public static int N;
    public static int[] List=new int[100];
    public static int Count=0;
    public static int flag=0;


    public  static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        N=scan.nextInt();

        for(int k=0;k<N;k++)
        {
            List[k]=scan.nextInt();
        }

        for(int k=0;k<N;k++)
        {
            BubbleSort(k);
        }

        for(int n=0;n<N;n++)
        {
            if(n!=N-1)
                System.out.print(List[n]+" ");
            if(n==N-1)
                System.out.println(List[n]);
        }
        System.out.println(Count);

    }

    public static void BubbleSort(int j)
    {
            for(int k=N-1;k>=1;k--)
            {
                flag=0;
                if(List[k]<List[k-1])
                {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                }
                if(flag==1) Count++;
            }
    }
} Main public static int N; N public static int[] List=new int[100]; List new int[100] 100 public static int Count=0; Count 0 public static int flag=0; flag 0 public  static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        N=scan.nextInt();

        for(int k=0;k<N;k++)
        {
            List[k]=scan.nextInt();
        }

        for(int k=0;k<N;k++)
        {
            BubbleSort(k);
        }

        for(int n=0;n<N;n++)
        {
            if(n!=N-1)
                System.out.print(List[n]+" ");
            if(n==N-1)
                System.out.println(List[n]);
        }
        System.out.println(Count);

    } main {
        Scanner scan=new Scanner(System.in);
        N=scan.nextInt();

        for(int k=0;k<N;k++)
        {
            List[k]=scan.nextInt();
        }

        for(int k=0;k<N;k++)
        {
            BubbleSort(k);
        }

        for(int n=0;n<N;n++)
        {
            if(n!=N-1)
                System.out.print(List[n]+" ");
            if(n==N-1)
                System.out.println(List[n]);
        }
        System.out.println(Count);

    } Scanner scan=new Scanner(System.in); scan new Scanner(System.in) N=scan.nextInt() N scan.nextInt() scan.nextInt scan for(int k=0;k<N;k++)
        {
            List[k]=scan.nextInt();
        } int k=0; int k=0; k 0 k<N k N k++ k++ k {
            List[k]=scan.nextInt();
        } {
            List[k]=scan.nextInt();
        } List[k]=scan.nextInt() List[k] List k scan.nextInt() scan.nextInt scan for(int k=0;k<N;k++)
        {
            BubbleSort(k);
        } int k=0; int k=0; k 0 k<N k N k++ k++ k {
            BubbleSort(k);
        } {
            BubbleSort(k);
        } BubbleSort(k) BubbleSort k for(int n=0;n<N;n++)
        {
            if(n!=N-1)
                System.out.print(List[n]+" ");
            if(n==N-1)
                System.out.println(List[n]);
        } int n=0; int n=0; n 0 n<N n N n++ n++ n {
            if(n!=N-1)
                System.out.print(List[n]+" ");
            if(n==N-1)
                System.out.println(List[n]);
        } {
            if(n!=N-1)
                System.out.print(List[n]+" ");
            if(n==N-1)
                System.out.println(List[n]);
        } if(n!=N-1)
                System.out.print(List[n]+" "); n!=N-1 n N-1 N 1 System.out.print(List[n]+" ") System.out.print System.out System System.out List[n]+" " List[n] List n " " if(n==N-1)
                System.out.println(List[n]); n==N-1 n N-1 N 1 System.out.println(List[n]) System.out.println System.out System System.out List[n] List n System.out.println(Count) System.out.println System.out System System.out Count String[] args args public static void BubbleSort(int j)
    {
            for(int k=N-1;k>=1;k--)
            {
                flag=0;
                if(List[k]<List[k-1])
                {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                }
                if(flag==1) Count++;
            }
    } BubbleSort {
            for(int k=N-1;k>=1;k--)
            {
                flag=0;
                if(List[k]<List[k-1])
                {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                }
                if(flag==1) Count++;
            }
    } for(int k=N-1;k>=1;k--)
            {
                flag=0;
                if(List[k]<List[k-1])
                {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                }
                if(flag==1) Count++;
            } int k=N-1; int k=N-1; k N-1 N 1 k>=1 k 1 k-- k-- k {
                flag=0;
                if(List[k]<List[k-1])
                {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                }
                if(flag==1) Count++;
            } {
                flag=0;
                if(List[k]<List[k-1])
                {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                }
                if(flag==1) Count++;
            } flag=0 flag 0 if(List[k]<List[k-1])
                {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                } List[k]<List[k-1] List[k] List k List[k-1] List k-1 k 1 {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                } int tmp=List[k]; tmp List[k] List k List[k]=List[k-1] List[k] List k List[k-1] List k-1 k 1 List[k-1]=tmp List[k-1] List k-1 k 1 tmp flag=1 flag 1 if(flag==1) Count++; flag==1 flag 1 Count++ Count int j j public class Main
{
    public static int N;
    public static int[] List=new int[100];
    public static int Count=0;
    public static int flag=0;


    public  static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        N=scan.nextInt();

        for(int k=0;k<N;k++)
        {
            List[k]=scan.nextInt();
        }

        for(int k=0;k<N;k++)
        {
            BubbleSort(k);
        }

        for(int n=0;n<N;n++)
        {
            if(n!=N-1)
                System.out.print(List[n]+" ");
            if(n==N-1)
                System.out.println(List[n]);
        }
        System.out.println(Count);

    }

    public static void BubbleSort(int j)
    {
            for(int k=N-1;k>=1;k--)
            {
                flag=0;
                if(List[k]<List[k-1])
                {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                }
                if(flag==1) Count++;
            }
    }
} public class Main
{
    public static int N;
    public static int[] List=new int[100];
    public static int Count=0;
    public static int flag=0;


    public  static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        N=scan.nextInt();

        for(int k=0;k<N;k++)
        {
            List[k]=scan.nextInt();
        }

        for(int k=0;k<N;k++)
        {
            BubbleSort(k);
        }

        for(int n=0;n<N;n++)
        {
            if(n!=N-1)
                System.out.print(List[n]+" ");
            if(n==N-1)
                System.out.println(List[n]);
        }
        System.out.println(Count);

    }

    public static void BubbleSort(int j)
    {
            for(int k=N-1;k>=1;k--)
            {
                flag=0;
                if(List[k]<List[k-1])
                {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                }
                if(flag==1) Count++;
            }
    }
} Main
import java.util.Scanner;

public class Main
{
    public static int N;
    public static int[] List=new int[100];
    public static int Count=0;
    public static int flag=0;


    public  static void main(String[] args)
    {
        Scanner scan=new Scanner(System.in);
        N=scan.nextInt();

        for(int k=0;k<N;k++)
        {
            List[k]=scan.nextInt();
        }

        for(int k=0;k<N;k++)
        {
            BubbleSort(k);
        }

        for(int n=0;n<N;n++)
        {
            if(n!=N-1)
                System.out.print(List[n]+" ");
            if(n==N-1)
                System.out.println(List[n]);
        }
        System.out.println(Count);

    }

    public static void BubbleSort(int j)
    {
            for(int k=N-1;k>=1;k--)
            {
                flag=0;
                if(List[k]<List[k-1])
                {
                    int tmp=List[k];
                    List[k]=List[k-1];
                    List[k-1]=tmp;
                    flag=1;
                }
                if(flag==1) Count++;
            }
    }
}