import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        int count;
        int[] array = new int[100];
        int key;
        int counter = 0;

        try{
            Scanner scan = new Scanner(System.in);
            String str = scan.next();

            count = Integer.parseInt(str);

            for(int i = 0; i < count; i++){
                str = scan.next();
                array[i] = Integer.parseInt(str);
            }

            //Sort Part
            for(int i = 0; i < count - 1; i++){
                for(int j = count - 1; j > i; j--){
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                }
                //System.out.println("OK");
            }

            for(int i = 0; i < count; i++){
                if(i == count - 1){
                    System.out.println(array[i]);
                }else{
                    System.out.print(array[i] + " ");
                }
            }

            System.out.println(counter);

        }catch(Exception e){
            System.out.println("ERROR");
        }

    }
}
 import java.util.*; util.* java import java.io.*; io.* java class Main{
    public static void main(String[] args){
        int count;
        int[] array = new int[100];
        int key;
        int counter = 0;

        try{
            Scanner scan = new Scanner(System.in);
            String str = scan.next();

            count = Integer.parseInt(str);

            for(int i = 0; i < count; i++){
                str = scan.next();
                array[i] = Integer.parseInt(str);
            }

            //Sort Part
            for(int i = 0; i < count - 1; i++){
                for(int j = count - 1; j > i; j--){
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                }
                //System.out.println("OK");
            }

            for(int i = 0; i < count; i++){
                if(i == count - 1){
                    System.out.println(array[i]);
                }else{
                    System.out.print(array[i] + " ");
                }
            }

            System.out.println(counter);

        }catch(Exception e){
            System.out.println("ERROR");
        }

    }
} Main public static void main(String[] args){
        int count;
        int[] array = new int[100];
        int key;
        int counter = 0;

        try{
            Scanner scan = new Scanner(System.in);
            String str = scan.next();

            count = Integer.parseInt(str);

            for(int i = 0; i < count; i++){
                str = scan.next();
                array[i] = Integer.parseInt(str);
            }

            //Sort Part
            for(int i = 0; i < count - 1; i++){
                for(int j = count - 1; j > i; j--){
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                }
                //System.out.println("OK");
            }

            for(int i = 0; i < count; i++){
                if(i == count - 1){
                    System.out.println(array[i]);
                }else{
                    System.out.print(array[i] + " ");
                }
            }

            System.out.println(counter);

        }catch(Exception e){
            System.out.println("ERROR");
        }

    } main {
        int count;
        int[] array = new int[100];
        int key;
        int counter = 0;

        try{
            Scanner scan = new Scanner(System.in);
            String str = scan.next();

            count = Integer.parseInt(str);

            for(int i = 0; i < count; i++){
                str = scan.next();
                array[i] = Integer.parseInt(str);
            }

            //Sort Part
            for(int i = 0; i < count - 1; i++){
                for(int j = count - 1; j > i; j--){
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                }
                //System.out.println("OK");
            }

            for(int i = 0; i < count; i++){
                if(i == count - 1){
                    System.out.println(array[i]);
                }else{
                    System.out.print(array[i] + " ");
                }
            }

            System.out.println(counter);

        }catch(Exception e){
            System.out.println("ERROR");
        }

    } int count; count int[] array = new int[100]; array new int[100] 100 int key; key int counter = 0; counter 0 try{
            Scanner scan = new Scanner(System.in);
            String str = scan.next();

            count = Integer.parseInt(str);

            for(int i = 0; i < count; i++){
                str = scan.next();
                array[i] = Integer.parseInt(str);
            }

            //Sort Part
            for(int i = 0; i < count - 1; i++){
                for(int j = count - 1; j > i; j--){
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                }
                //System.out.println("OK");
            }

            for(int i = 0; i < count; i++){
                if(i == count - 1){
                    System.out.println(array[i]);
                }else{
                    System.out.print(array[i] + " ");
                }
            }

            System.out.println(counter);

        }catch(Exception e){
            System.out.println("ERROR");
        } catch(Exception e){
            System.out.println("ERROR");
        } Exception e {
            System.out.println("ERROR");
        } System.out.println("ERROR") System.out.println System.out System System.out "ERROR" {
            Scanner scan = new Scanner(System.in);
            String str = scan.next();

            count = Integer.parseInt(str);

            for(int i = 0; i < count; i++){
                str = scan.next();
                array[i] = Integer.parseInt(str);
            }

            //Sort Part
            for(int i = 0; i < count - 1; i++){
                for(int j = count - 1; j > i; j--){
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                }
                //System.out.println("OK");
            }

            for(int i = 0; i < count; i++){
                if(i == count - 1){
                    System.out.println(array[i]);
                }else{
                    System.out.print(array[i] + " ");
                }
            }

            System.out.println(counter);

        } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) String str = scan.next(); str scan.next() scan.next scan count = Integer.parseInt(str) count Integer.parseInt(str) Integer.parseInt Integer str for(int i = 0; i < count; i++){
                str = scan.next();
                array[i] = Integer.parseInt(str);
            } int i = 0; int i = 0; i 0 i < count i count i++ i++ i {
                str = scan.next();
                array[i] = Integer.parseInt(str);
            } {
                str = scan.next();
                array[i] = Integer.parseInt(str);
            } str = scan.next() str scan.next() scan.next scan array[i] = Integer.parseInt(str) array[i] array i Integer.parseInt(str) Integer.parseInt Integer str for(int i = 0; i < count - 1; i++){
                for(int j = count - 1; j > i; j--){
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                }
                //System.out.println("OK");
            } int i = 0; int i = 0; i 0 i < count - 1 i count - 1 count 1 i++ i++ i {
                for(int j = count - 1; j > i; j--){
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                }
                //System.out.println("OK");
            } {
                for(int j = count - 1; j > i; j--){
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                }
                //System.out.println("OK");
            } for(int j = count - 1; j > i; j--){
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                } int j = count - 1; int j = count - 1; j count - 1 count 1 j > i j i j-- j-- j {
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                } {
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                } if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    } array[j] < array[j-1] array[j] array j array[j-1] array j-1 j 1 {
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    } key = array[j-1] key array[j-1] array j-1 j 1 array[j-1] = array[j] array[j-1] array j-1 j 1 array[j] array j array[j] = key array[j] array j key counter++ counter for(int i = 0; i < count; i++){
                if(i == count - 1){
                    System.out.println(array[i]);
                }else{
                    System.out.print(array[i] + " ");
                }
            } int i = 0; int i = 0; i 0 i < count i count i++ i++ i {
                if(i == count - 1){
                    System.out.println(array[i]);
                }else{
                    System.out.print(array[i] + " ");
                }
            } {
                if(i == count - 1){
                    System.out.println(array[i]);
                }else{
                    System.out.print(array[i] + " ");
                }
            } if(i == count - 1){
                    System.out.println(array[i]);
                }else{
                    System.out.print(array[i] + " ");
                } i == count - 1 i count - 1 count 1 {
                    System.out.println(array[i]);
                } System.out.println(array[i]) System.out.println System.out System System.out array[i] 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(counter) System.out.println System.out System System.out counter String[] args args
import java.util.*;
import java.io.*;

class Main{
    public static void main(String[] args){
        int count;
        int[] array = new int[100];
        int key;
        int counter = 0;

        try{
            Scanner scan = new Scanner(System.in);
            String str = scan.next();

            count = Integer.parseInt(str);

            for(int i = 0; i < count; i++){
                str = scan.next();
                array[i] = Integer.parseInt(str);
            }

            //Sort Part
            for(int i = 0; i < count - 1; i++){
                for(int j = count - 1; j > i; j--){
                    //System.out.println("---OK");
                    if(array[j] < array[j-1]){
                        key = array[j-1];
                        array[j-1] = array[j];
                        array[j] = key;
                        counter++;
                    }
                }
                //System.out.println("OK");
            }

            for(int i = 0; i < count; i++){
                if(i == count - 1){
                    System.out.println(array[i]);
                }else{
                    System.out.print(array[i] + " ");
                }
            }

            System.out.println(counter);

        }catch(Exception e){
            System.out.println("ERROR");
        }

    }
}

