import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));

        int len = Integer.parseInt(reader.readLine());
        int[] arr = new int[len];

        String arrStr = reader.readLine();
        StringTokenizer tokenizer = new StringTokenizer(arrStr, " ");

        int i = 0;
        while (tokenizer.hasMoreElements()) {
            arr[i++] = Integer.parseInt((String) tokenizer.nextElement());
        }

//         int[] arr = {1,2,3,4,5};
//         int len = arr.length;

        bubblesort(arr, len);
    }
    

    private static void bubblesort(int[] arr, int len) {
      
        int swapCnt = 0;
        
        for (int i = 0; i < len - 1; i++) {
            
//            System.out.println("===========================");
            for (int j = (len - 1); j > i ; j--) {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            }
            
            
        }
        printArr(arr);
        System.out.println(swapCnt);
    }

    static void printArr(int[] arr) {
        String msg = "";
        for (int i = 0; i < arr.length; i++) {
            msg += arr[i];
            if (i == arr.length - 1) {
                break;
            }
            msg += " ";
        }

        System.out.println(msg);
    }

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.StringTokenizer; StringTokenizer java.util public class Main {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));

        int len = Integer.parseInt(reader.readLine());
        int[] arr = new int[len];

        String arrStr = reader.readLine();
        StringTokenizer tokenizer = new StringTokenizer(arrStr, " ");

        int i = 0;
        while (tokenizer.hasMoreElements()) {
            arr[i++] = Integer.parseInt((String) tokenizer.nextElement());
        }

//         int[] arr = {1,2,3,4,5};
//         int len = arr.length;

        bubblesort(arr, len);
    }
    

    private static void bubblesort(int[] arr, int len) {
      
        int swapCnt = 0;
        
        for (int i = 0; i < len - 1; i++) {
            
//            System.out.println("===========================");
            for (int j = (len - 1); j > i ; j--) {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            }
            
            
        }
        printArr(arr);
        System.out.println(swapCnt);
    }

    static void printArr(int[] arr) {
        String msg = "";
        for (int i = 0; i < arr.length; i++) {
            msg += arr[i];
            if (i == arr.length - 1) {
                break;
            }
            msg += " ";
        }

        System.out.println(msg);
    }

} Main /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));

        int len = Integer.parseInt(reader.readLine());
        int[] arr = new int[len];

        String arrStr = reader.readLine();
        StringTokenizer tokenizer = new StringTokenizer(arrStr, " ");

        int i = 0;
        while (tokenizer.hasMoreElements()) {
            arr[i++] = Integer.parseInt((String) tokenizer.nextElement());
        }

//         int[] arr = {1,2,3,4,5};
//         int len = arr.length;

        bubblesort(arr, len);
    } main {

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));

        int len = Integer.parseInt(reader.readLine());
        int[] arr = new int[len];

        String arrStr = reader.readLine();
        StringTokenizer tokenizer = new StringTokenizer(arrStr, " ");

        int i = 0;
        while (tokenizer.hasMoreElements()) {
            arr[i++] = Integer.parseInt((String) tokenizer.nextElement());
        }

//         int[] arr = {1,2,3,4,5};
//         int len = arr.length;

        bubblesort(arr, len);
    } BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in)); reader new BufferedReader(new InputStreamReader(
                System.in)) int len = Integer.parseInt(reader.readLine()); len Integer.parseInt(reader.readLine()) Integer.parseInt Integer reader.readLine() reader.readLine reader int[] arr = new int[len]; arr new int[len] len String arrStr = reader.readLine(); arrStr reader.readLine() reader.readLine reader StringTokenizer tokenizer = new StringTokenizer(arrStr, " "); tokenizer new StringTokenizer(arrStr, " ") int i = 0; i 0 while (tokenizer.hasMoreElements()) {
            arr[i++] = Integer.parseInt((String) tokenizer.nextElement());
        } tokenizer.hasMoreElements() tokenizer.hasMoreElements tokenizer {
            arr[i++] = Integer.parseInt((String) tokenizer.nextElement());
        } arr[i++] = Integer.parseInt((String) tokenizer.nextElement()) arr[i++] arr i++ i Integer.parseInt((String) tokenizer.nextElement()) Integer.parseInt Integer (String) tokenizer.nextElement() tokenizer.nextElement tokenizer bubblesort(arr, len) bubblesort arr len String[] args args private static void bubblesort(int[] arr, int len) {
      
        int swapCnt = 0;
        
        for (int i = 0; i < len - 1; i++) {
            
//            System.out.println("===========================");
            for (int j = (len - 1); j > i ; j--) {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            }
            
            
        }
        printArr(arr);
        System.out.println(swapCnt);
    } bubblesort {
      
        int swapCnt = 0;
        
        for (int i = 0; i < len - 1; i++) {
            
//            System.out.println("===========================");
            for (int j = (len - 1); j > i ; j--) {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            }
            
            
        }
        printArr(arr);
        System.out.println(swapCnt);
    } int swapCnt = 0; swapCnt 0 for (int i = 0; i < len - 1; i++) {
            
//            System.out.println("===========================");
            for (int j = (len - 1); j > i ; j--) {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            }
            
            
        } int i = 0; int i = 0; i 0 i < len - 1 i len - 1 len 1 i++ i++ i {
            
//            System.out.println("===========================");
            for (int j = (len - 1); j > i ; j--) {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            }
            
            
        } {
            
//            System.out.println("===========================");
            for (int j = (len - 1); j > i ; j--) {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            }
            
            
        } for (int j = (len - 1); j > i ; j--) {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            } int j = (len - 1); int j = (len - 1); j (len - 1) len 1 j > i j i j-- j-- j {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            } {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            } int current = arr[j]; current arr[j] arr j int target = arr[j - 1]; target arr[j - 1] arr j - 1 j 1 if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                } target > current target current {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                } swapCnt++ swapCnt int swap = arr[j -1]; swap arr[j -1] arr j -1 j 1 arr[j - 1] = arr[j] arr[j - 1] arr j - 1 j 1 arr[j] arr j arr[j] = swap arr[j] arr j swap printArr(arr) printArr arr System.out.println(swapCnt) System.out.println System.out System System.out swapCnt int[] arr arr int len len static void printArr(int[] arr) {
        String msg = "";
        for (int i = 0; i < arr.length; i++) {
            msg += arr[i];
            if (i == arr.length - 1) {
                break;
            }
            msg += " ";
        }

        System.out.println(msg);
    } printArr {
        String msg = "";
        for (int i = 0; i < arr.length; i++) {
            msg += arr[i];
            if (i == arr.length - 1) {
                break;
            }
            msg += " ";
        }

        System.out.println(msg);
    } String msg = ""; msg "" for (int i = 0; i < arr.length; i++) {
            msg += arr[i];
            if (i == arr.length - 1) {
                break;
            }
            msg += " ";
        } int i = 0; int i = 0; i 0 i < arr.length i arr.length arr arr.length i++ i++ i {
            msg += arr[i];
            if (i == arr.length - 1) {
                break;
            }
            msg += " ";
        } {
            msg += arr[i];
            if (i == arr.length - 1) {
                break;
            }
            msg += " ";
        } msg += arr[i] msg arr[i] arr i if (i == arr.length - 1) {
                break;
            } i == arr.length - 1 i arr.length - 1 arr.length arr arr.length 1 {
                break;
            } break; msg += " " msg " " System.out.println(msg) System.out.println System.out System System.out msg int[] arr arr public class Main {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));

        int len = Integer.parseInt(reader.readLine());
        int[] arr = new int[len];

        String arrStr = reader.readLine();
        StringTokenizer tokenizer = new StringTokenizer(arrStr, " ");

        int i = 0;
        while (tokenizer.hasMoreElements()) {
            arr[i++] = Integer.parseInt((String) tokenizer.nextElement());
        }

//         int[] arr = {1,2,3,4,5};
//         int len = arr.length;

        bubblesort(arr, len);
    }
    

    private static void bubblesort(int[] arr, int len) {
      
        int swapCnt = 0;
        
        for (int i = 0; i < len - 1; i++) {
            
//            System.out.println("===========================");
            for (int j = (len - 1); j > i ; j--) {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            }
            
            
        }
        printArr(arr);
        System.out.println(swapCnt);
    }

    static void printArr(int[] arr) {
        String msg = "";
        for (int i = 0; i < arr.length; i++) {
            msg += arr[i];
            if (i == arr.length - 1) {
                break;
            }
            msg += " ";
        }

        System.out.println(msg);
    }

} public class Main {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));

        int len = Integer.parseInt(reader.readLine());
        int[] arr = new int[len];

        String arrStr = reader.readLine();
        StringTokenizer tokenizer = new StringTokenizer(arrStr, " ");

        int i = 0;
        while (tokenizer.hasMoreElements()) {
            arr[i++] = Integer.parseInt((String) tokenizer.nextElement());
        }

//         int[] arr = {1,2,3,4,5};
//         int len = arr.length;

        bubblesort(arr, len);
    }
    

    private static void bubblesort(int[] arr, int len) {
      
        int swapCnt = 0;
        
        for (int i = 0; i < len - 1; i++) {
            
//            System.out.println("===========================");
            for (int j = (len - 1); j > i ; j--) {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            }
            
            
        }
        printArr(arr);
        System.out.println(swapCnt);
    }

    static void printArr(int[] arr) {
        String msg = "";
        for (int i = 0; i < arr.length; i++) {
            msg += arr[i];
            if (i == arr.length - 1) {
                break;
            }
            msg += " ";
        }

        System.out.println(msg);
    }

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    /**
     * @param args
     * @throws IOException
     */
    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(
                System.in));

        int len = Integer.parseInt(reader.readLine());
        int[] arr = new int[len];

        String arrStr = reader.readLine();
        StringTokenizer tokenizer = new StringTokenizer(arrStr, " ");

        int i = 0;
        while (tokenizer.hasMoreElements()) {
            arr[i++] = Integer.parseInt((String) tokenizer.nextElement());
        }

//         int[] arr = {1,2,3,4,5};
//         int len = arr.length;

        bubblesort(arr, len);
    }
    

    private static void bubblesort(int[] arr, int len) {
      
        int swapCnt = 0;
        
        for (int i = 0; i < len - 1; i++) {
            
//            System.out.println("===========================");
            for (int j = (len - 1); j > i ; j--) {

//                System.out.println("i:" + i + " j:" + j);
                
                int current = arr[j];
                int target = arr[j - 1];

                if (target > current) {

                    swapCnt++;

                    int swap = arr[j -1];
                    arr[j - 1] = arr[j];
                    arr[j] = swap;
                }
                
                
            }
            
            
        }
        printArr(arr);
        System.out.println(swapCnt);
    }

    static void printArr(int[] arr) {
        String msg = "";
        for (int i = 0; i < arr.length; i++) {
            msg += arr[i];
            if (i == arr.length - 1) {
                break;
            }
            msg += " ";
        }

        System.out.println(msg);
    }

}