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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> nums = new ArrayList<>();
        for(int i=0; i<n; ++i) {
            nums.add(sc.nextInt());
        }

        boolean flag = true;
        int inversion = 0;
        int index = 0;
        while(flag) {
            flag = false;
            for(int i=n-1; i>index;--i) {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            }
            index++;
        }

        for(int i=0; i<n-1; ++i) {
            System.out.print(nums.get(i) + " ");
        }
        System.out.println(nums.get(n-1));
        System.out.println(inversion);
    }
} import java.io.*; io.* java import java.util.*; util.* java public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> nums = new ArrayList<>();
        for(int i=0; i<n; ++i) {
            nums.add(sc.nextInt());
        }

        boolean flag = true;
        int inversion = 0;
        int index = 0;
        while(flag) {
            flag = false;
            for(int i=n-1; i>index;--i) {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            }
            index++;
        }

        for(int i=0; i<n-1; ++i) {
            System.out.print(nums.get(i) + " ");
        }
        System.out.println(nums.get(n-1));
        System.out.println(inversion);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> nums = new ArrayList<>();
        for(int i=0; i<n; ++i) {
            nums.add(sc.nextInt());
        }

        boolean flag = true;
        int inversion = 0;
        int index = 0;
        while(flag) {
            flag = false;
            for(int i=n-1; i>index;--i) {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            }
            index++;
        }

        for(int i=0; i<n-1; ++i) {
            System.out.print(nums.get(i) + " ");
        }
        System.out.println(nums.get(n-1));
        System.out.println(inversion);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> nums = new ArrayList<>();
        for(int i=0; i<n; ++i) {
            nums.add(sc.nextInt());
        }

        boolean flag = true;
        int inversion = 0;
        int index = 0;
        while(flag) {
            flag = false;
            for(int i=n-1; i>index;--i) {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            }
            index++;
        }

        for(int i=0; i<n-1; ++i) {
            System.out.print(nums.get(i) + " ");
        }
        System.out.println(nums.get(n-1));
        System.out.println(inversion);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc List<Integer> nums = new ArrayList<>(); nums new ArrayList<>() for(int i=0; i<n; ++i) {
            nums.add(sc.nextInt());
        } int i=0; int i=0; i 0 i<n i n ++i ++i i {
            nums.add(sc.nextInt());
        } {
            nums.add(sc.nextInt());
        } nums.add(sc.nextInt()) nums.add nums sc.nextInt() sc.nextInt sc boolean flag = true; flag true int inversion = 0; inversion 0 int index = 0; index 0 while(flag) {
            flag = false;
            for(int i=n-1; i>index;--i) {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            }
            index++;
        } flag {
            flag = false;
            for(int i=n-1; i>index;--i) {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            }
            index++;
        } flag = false flag false for(int i=n-1; i>index;--i) {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            } int i=n-1; int i=n-1; i n-1 n 1 i>index i index --i --i i {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            } {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            } if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                } nums.get(i-1) > nums.get(i) nums.get(i-1) nums.get nums i-1 i 1 nums.get(i) nums.get nums i {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                } int tmp = nums.get(i); tmp nums.get(i) nums.get nums i nums.set(i, nums.get(i-1)) nums.set nums i nums.get(i-1) nums.get nums i-1 i 1 nums.set(i-1, tmp) nums.set nums i-1 i 1 tmp inversion++ inversion flag = true flag true index++ index for(int i=0; i<n-1; ++i) {
            System.out.print(nums.get(i) + " ");
        } int i=0; int i=0; i 0 i<n-1 i n-1 n 1 ++i ++i i {
            System.out.print(nums.get(i) + " ");
        } {
            System.out.print(nums.get(i) + " ");
        } System.out.print(nums.get(i) + " ") System.out.print System.out System System.out nums.get(i) + " " nums.get(i) nums.get nums i " " System.out.println(nums.get(n-1)) System.out.println System.out System System.out nums.get(n-1) nums.get nums n-1 n 1 System.out.println(inversion) System.out.println System.out System System.out inversion String[] args args public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> nums = new ArrayList<>();
        for(int i=0; i<n; ++i) {
            nums.add(sc.nextInt());
        }

        boolean flag = true;
        int inversion = 0;
        int index = 0;
        while(flag) {
            flag = false;
            for(int i=n-1; i>index;--i) {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            }
            index++;
        }

        for(int i=0; i<n-1; ++i) {
            System.out.print(nums.get(i) + " ");
        }
        System.out.println(nums.get(n-1));
        System.out.println(inversion);
    }
} public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> nums = new ArrayList<>();
        for(int i=0; i<n; ++i) {
            nums.add(sc.nextInt());
        }

        boolean flag = true;
        int inversion = 0;
        int index = 0;
        while(flag) {
            flag = false;
            for(int i=n-1; i>index;--i) {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            }
            index++;
        }

        for(int i=0; i<n-1; ++i) {
            System.out.print(nums.get(i) + " ");
        }
        System.out.println(nums.get(n-1));
        System.out.println(inversion);
    }
} Main
import java.io.*;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        List<Integer> nums = new ArrayList<>();
        for(int i=0; i<n; ++i) {
            nums.add(sc.nextInt());
        }

        boolean flag = true;
        int inversion = 0;
        int index = 0;
        while(flag) {
            flag = false;
            for(int i=n-1; i>index;--i) {
                if(nums.get(i-1) > nums.get(i)) {
                    int tmp = nums.get(i);
                    nums.set(i, nums.get(i-1));
                    nums.set(i-1, tmp);
                    inversion++;
                    flag = true;
                }
            }
            index++;
        }

        for(int i=0; i<n-1; ++i) {
            System.out.print(nums.get(i) + " ");
        }
        System.out.println(nums.get(n-1));
        System.out.println(inversion);
    }
}