import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
        int n = Integer.parseInt(cin.next());
        int[] array = new int[n];
        cin.nextLine();
        for (int i = 0; i < n; i++)
        {
            array[i] = cin.nextInt();
        }

        int cnt = bubbleSort(array, n);
        for (int i = 0; i < n; i++)
        {
            System.out.print(array[i]);
            if (i != n - 1)
            {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(cnt);
    }

    // Return : count
    public static int bubbleSort(int[] A, int N)
    {
        int cnt = 0;

        int flag = 1;
        while (flag == 1)
        {
            flag = 0;
            for (int j = N - 1; j > 0; j--)
            {
                if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            }
        }
        return cnt;
    }
} import java.util.Scanner; Scanner java.util public class Main
{
    public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
        int n = Integer.parseInt(cin.next());
        int[] array = new int[n];
        cin.nextLine();
        for (int i = 0; i < n; i++)
        {
            array[i] = cin.nextInt();
        }

        int cnt = bubbleSort(array, n);
        for (int i = 0; i < n; i++)
        {
            System.out.print(array[i]);
            if (i != n - 1)
            {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(cnt);
    }

    // Return : count
    public static int bubbleSort(int[] A, int N)
    {
        int cnt = 0;

        int flag = 1;
        while (flag == 1)
        {
            flag = 0;
            for (int j = N - 1; j > 0; j--)
            {
                if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            }
        }
        return cnt;
    }
} Main public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
        int n = Integer.parseInt(cin.next());
        int[] array = new int[n];
        cin.nextLine();
        for (int i = 0; i < n; i++)
        {
            array[i] = cin.nextInt();
        }

        int cnt = bubbleSort(array, n);
        for (int i = 0; i < n; i++)
        {
            System.out.print(array[i]);
            if (i != n - 1)
            {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(cnt);
    } main {
        Scanner cin = new Scanner(System.in);
        int n = Integer.parseInt(cin.next());
        int[] array = new int[n];
        cin.nextLine();
        for (int i = 0; i < n; i++)
        {
            array[i] = cin.nextInt();
        }

        int cnt = bubbleSort(array, n);
        for (int i = 0; i < n; i++)
        {
            System.out.print(array[i]);
            if (i != n - 1)
            {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(cnt);
    } Scanner cin = new Scanner(System.in); cin new Scanner(System.in) int n = Integer.parseInt(cin.next()); n Integer.parseInt(cin.next()) Integer.parseInt Integer cin.next() cin.next cin int[] array = new int[n]; array new int[n] n cin.nextLine() cin.nextLine cin for (int i = 0; i < n; i++)
        {
            array[i] = cin.nextInt();
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            array[i] = cin.nextInt();
        } {
            array[i] = cin.nextInt();
        } array[i] = cin.nextInt() array[i] array i cin.nextInt() cin.nextInt cin int cnt = bubbleSort(array, n); cnt bubbleSort(array, n) bubbleSort array n for (int i = 0; i < n; i++)
        {
            System.out.print(array[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(array[i]);
            if (i != n - 1)
            {
                System.out.print(" ");
            }
        } {
            System.out.print(array[i]);
            if (i != n - 1)
            {
                System.out.print(" ");
            }
        } System.out.print(array[i]) System.out.print System.out System System.out array[i] array i if (i != n - 1)
            {
                System.out.print(" ");
            } i != n - 1 i n - 1 n 1 {
                System.out.print(" ");
            } 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(cnt) System.out.println System.out System System.out cnt String[] args args // Return : count
    public static int bubbleSort(int[] A, int N)
    {
        int cnt = 0;

        int flag = 1;
        while (flag == 1)
        {
            flag = 0;
            for (int j = N - 1; j > 0; j--)
            {
                if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            }
        }
        return cnt;
    } bubbleSort {
        int cnt = 0;

        int flag = 1;
        while (flag == 1)
        {
            flag = 0;
            for (int j = N - 1; j > 0; j--)
            {
                if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            }
        }
        return cnt;
    } int cnt = 0; cnt 0 int flag = 1; flag 1 while (flag == 1)
        {
            flag = 0;
            for (int j = N - 1; j > 0; j--)
            {
                if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            }
        } flag == 1 flag 1 {
            flag = 0;
            for (int j = N - 1; j > 0; j--)
            {
                if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            }
        } flag = 0 flag 0 for (int j = N - 1; j > 0; j--)
            {
                if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            } 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])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            } {
                if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            } if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                } A[j] < A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                } int 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 flag = 1 flag 1 cnt++ cnt return cnt; cnt int[] A A int N N public class Main
{
    public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
        int n = Integer.parseInt(cin.next());
        int[] array = new int[n];
        cin.nextLine();
        for (int i = 0; i < n; i++)
        {
            array[i] = cin.nextInt();
        }

        int cnt = bubbleSort(array, n);
        for (int i = 0; i < n; i++)
        {
            System.out.print(array[i]);
            if (i != n - 1)
            {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(cnt);
    }

    // Return : count
    public static int bubbleSort(int[] A, int N)
    {
        int cnt = 0;

        int flag = 1;
        while (flag == 1)
        {
            flag = 0;
            for (int j = N - 1; j > 0; j--)
            {
                if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            }
        }
        return cnt;
    }
} public class Main
{
    public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
        int n = Integer.parseInt(cin.next());
        int[] array = new int[n];
        cin.nextLine();
        for (int i = 0; i < n; i++)
        {
            array[i] = cin.nextInt();
        }

        int cnt = bubbleSort(array, n);
        for (int i = 0; i < n; i++)
        {
            System.out.print(array[i]);
            if (i != n - 1)
            {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(cnt);
    }

    // Return : count
    public static int bubbleSort(int[] A, int N)
    {
        int cnt = 0;

        int flag = 1;
        while (flag == 1)
        {
            flag = 0;
            for (int j = N - 1; j > 0; j--)
            {
                if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            }
        }
        return cnt;
    }
} Main
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner cin = new Scanner(System.in);
        int n = Integer.parseInt(cin.next());
        int[] array = new int[n];
        cin.nextLine();
        for (int i = 0; i < n; i++)
        {
            array[i] = cin.nextInt();
        }

        int cnt = bubbleSort(array, n);
        for (int i = 0; i < n; i++)
        {
            System.out.print(array[i]);
            if (i != n - 1)
            {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(cnt);
    }

    // Return : count
    public static int bubbleSort(int[] A, int N)
    {
        int cnt = 0;

        int flag = 1;
        while (flag == 1)
        {
            flag = 0;
            for (int j = N - 1; j > 0; j--)
            {
                if (A[j] < A[j - 1])
                {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = 1;
                    cnt++;
                }
            }
        }
        return cnt;
    }
}