import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int z = sc.nextInt();
        int[] ary = new int[z];
        for(int i = 0 ; i < ary.length; i++){
            ary[i] = sc.nextInt();
        }
        int count = 0;
        for(int j = 0; j < ary.length; j++){
            for(int i = ary.length-1; i > j; i--){
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            }
        }
        for(int i = 0; i < ary.length; i++){
            build.append(ary[i]);
            build.append(i==ary.length-1 ? "\n" : " ");
        }
        build.append(count);
        System.out.println(build.toString());
    }
} import java.util.Scanner; Scanner java.util public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int z = sc.nextInt();
        int[] ary = new int[z];
        for(int i = 0 ; i < ary.length; i++){
            ary[i] = sc.nextInt();
        }
        int count = 0;
        for(int j = 0; j < ary.length; j++){
            for(int i = ary.length-1; i > j; i--){
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            }
        }
        for(int i = 0; i < ary.length; i++){
            build.append(ary[i]);
            build.append(i==ary.length-1 ? "\n" : " ");
        }
        build.append(count);
        System.out.println(build.toString());
    }
} Main public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int z = sc.nextInt();
        int[] ary = new int[z];
        for(int i = 0 ; i < ary.length; i++){
            ary[i] = sc.nextInt();
        }
        int count = 0;
        for(int j = 0; j < ary.length; j++){
            for(int i = ary.length-1; i > j; i--){
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            }
        }
        for(int i = 0; i < ary.length; i++){
            build.append(ary[i]);
            build.append(i==ary.length-1 ? "\n" : " ");
        }
        build.append(count);
        System.out.println(build.toString());
    } main {
        Scanner sc =new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int z = sc.nextInt();
        int[] ary = new int[z];
        for(int i = 0 ; i < ary.length; i++){
            ary[i] = sc.nextInt();
        }
        int count = 0;
        for(int j = 0; j < ary.length; j++){
            for(int i = ary.length-1; i > j; i--){
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            }
        }
        for(int i = 0; i < ary.length; i++){
            build.append(ary[i]);
            build.append(i==ary.length-1 ? "\n" : " ");
        }
        build.append(count);
        System.out.println(build.toString());
    } Scanner sc =new Scanner(System.in); sc new Scanner(System.in) StringBuilder build = new StringBuilder(); build new StringBuilder() int z = sc.nextInt(); z sc.nextInt() sc.nextInt sc int[] ary = new int[z]; ary new int[z] z for(int i = 0 ; i < ary.length; i++){
            ary[i] = sc.nextInt();
        } int i = 0 ; int i = 0 ; i 0 i < ary.length i ary.length ary ary.length i++ i++ i {
            ary[i] = sc.nextInt();
        } {
            ary[i] = sc.nextInt();
        } ary[i] = sc.nextInt() ary[i] ary i sc.nextInt() sc.nextInt sc int count = 0; count 0 for(int j = 0; j < ary.length; j++){
            for(int i = ary.length-1; i > j; i--){
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            }
        } int j = 0; int j = 0; j 0 j < ary.length j ary.length ary ary.length j++ j++ j {
            for(int i = ary.length-1; i > j; i--){
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            }
        } {
            for(int i = ary.length-1; i > j; i--){
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            }
        } for(int i = ary.length-1; i > j; i--){
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            } int i = ary.length-1; int i = ary.length-1; i ary.length-1 ary.length ary ary.length 1 i > j i j i-- i-- i {
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            } {
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            } if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                } ary[i] < ary[i-1] ary[i] ary i ary[i-1] ary i-1 i 1 {
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                } int temp = ary[i]; temp ary[i] ary i ary[i] = ary[i-1] ary[i] ary i ary[i-1] ary i-1 i 1 ary[i-1] = temp ary[i-1] ary i-1 i 1 temp count++ count for(int i = 0; i < ary.length; i++){
            build.append(ary[i]);
            build.append(i==ary.length-1 ? "\n" : " ");
        } int i = 0; int i = 0; i 0 i < ary.length i ary.length ary ary.length i++ i++ i {
            build.append(ary[i]);
            build.append(i==ary.length-1 ? "\n" : " ");
        } {
            build.append(ary[i]);
            build.append(i==ary.length-1 ? "\n" : " ");
        } build.append(ary[i]) build.append build ary[i] ary i build.append(i==ary.length-1 ? "\n" : " ") build.append build i==ary.length-1 ? "\n" : " " i==ary.length-1 i ary.length-1 ary.length ary ary.length 1 "\n" " " build.append(count) build.append build count System.out.println(build.toString()) System.out.println System.out System System.out build.toString() build.toString build String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int z = sc.nextInt();
        int[] ary = new int[z];
        for(int i = 0 ; i < ary.length; i++){
            ary[i] = sc.nextInt();
        }
        int count = 0;
        for(int j = 0; j < ary.length; j++){
            for(int i = ary.length-1; i > j; i--){
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            }
        }
        for(int i = 0; i < ary.length; i++){
            build.append(ary[i]);
            build.append(i==ary.length-1 ? "\n" : " ");
        }
        build.append(count);
        System.out.println(build.toString());
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int z = sc.nextInt();
        int[] ary = new int[z];
        for(int i = 0 ; i < ary.length; i++){
            ary[i] = sc.nextInt();
        }
        int count = 0;
        for(int j = 0; j < ary.length; j++){
            for(int i = ary.length-1; i > j; i--){
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            }
        }
        for(int i = 0; i < ary.length; i++){
            build.append(ary[i]);
            build.append(i==ary.length-1 ? "\n" : " ");
        }
        build.append(count);
        System.out.println(build.toString());
    }
} Main
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner sc =new Scanner(System.in);
        StringBuilder build = new StringBuilder();
        int z = sc.nextInt();
        int[] ary = new int[z];
        for(int i = 0 ; i < ary.length; i++){
            ary[i] = sc.nextInt();
        }
        int count = 0;
        for(int j = 0; j < ary.length; j++){
            for(int i = ary.length-1; i > j; i--){
                if(ary[i] < ary[i-1]){
                    int temp = ary[i];
                    ary[i] = ary[i-1];
                    ary[i-1] = temp;
                    count++;
                }
            }
        }
        for(int i = 0; i < ary.length; i++){
            build.append(ary[i]);
            build.append(i==ary.length-1 ? "\n" : " ");
        }
        build.append(count);
        System.out.println(build.toString());
    }
}