import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt();
                        int[] A = new int[N];
                        int[] B = new int[N];

                        for (int i = 0; i < N; i++) {
                                A[i] = sc.nextInt();
                                B[i] = A[i];
                        }
                        Arrays.sort(B);
                        for (int i = 0; i < N; i++) {
                                System.out.print(B[i] + (i == N-1 ? "\n" : " "));
                        }
                        System.out.println(bubbleSort(A, N));
                }
        }
        private static int bubbleSort(int[] A, int N) {
                boolean flag = true;
                int ans = 0;
                while (flag) {
                        flag = false;
                        for (int j = N - 1; j >= 1; j--) {
                                if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                }
                        }
                }
                return ans;
        }
} import java.util.*; util.* java class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt();
                        int[] A = new int[N];
                        int[] B = new int[N];

                        for (int i = 0; i < N; i++) {
                                A[i] = sc.nextInt();
                                B[i] = A[i];
                        }
                        Arrays.sort(B);
                        for (int i = 0; i < N; i++) {
                                System.out.print(B[i] + (i == N-1 ? "\n" : " "));
                        }
                        System.out.println(bubbleSort(A, N));
                }
        }
        private static int bubbleSort(int[] A, int N) {
                boolean flag = true;
                int ans = 0;
                while (flag) {
                        flag = false;
                        for (int j = N - 1; j >= 1; j--) {
                                if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                }
                        }
                }
                return ans;
        }
} Main public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt();
                        int[] A = new int[N];
                        int[] B = new int[N];

                        for (int i = 0; i < N; i++) {
                                A[i] = sc.nextInt();
                                B[i] = A[i];
                        }
                        Arrays.sort(B);
                        for (int i = 0; i < N; i++) {
                                System.out.print(B[i] + (i == N-1 ? "\n" : " "));
                        }
                        System.out.println(bubbleSort(A, N));
                }
        } main {
                try (Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt();
                        int[] A = new int[N];
                        int[] B = new int[N];

                        for (int i = 0; i < N; i++) {
                                A[i] = sc.nextInt();
                                B[i] = A[i];
                        }
                        Arrays.sort(B);
                        for (int i = 0; i < N; i++) {
                                System.out.print(B[i] + (i == N-1 ? "\n" : " "));
                        }
                        System.out.println(bubbleSort(A, N));
                }
        } try (Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt();
                        int[] A = new int[N];
                        int[] B = new int[N];

                        for (int i = 0; i < N; i++) {
                                A[i] = sc.nextInt();
                                B[i] = A[i];
                        }
                        Arrays.sort(B);
                        for (int i = 0; i < N; i++) {
                                System.out.print(B[i] + (i == N-1 ? "\n" : " "));
                        }
                        System.out.println(bubbleSort(A, N));
                } {
                        int N = sc.nextInt();
                        int[] A = new int[N];
                        int[] B = new int[N];

                        for (int i = 0; i < N; i++) {
                                A[i] = sc.nextInt();
                                B[i] = A[i];
                        }
                        Arrays.sort(B);
                        for (int i = 0; i < N; i++) {
                                System.out.print(B[i] + (i == N-1 ? "\n" : " "));
                        }
                        System.out.println(bubbleSort(A, N));
                } Scanner sc = new Scanner(System.in) Scanner sc = new Scanner(System.in) new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] A = new int[N]; A new int[N] N int[] B = new int[N]; B new int[N] N for (int i = 0; i < N; i++) {
                                A[i] = sc.nextInt();
                                B[i] = A[i];
                        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                                A[i] = sc.nextInt();
                                B[i] = A[i];
                        } {
                                A[i] = sc.nextInt();
                                B[i] = A[i];
                        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc B[i] = A[i] B[i] B i A[i] A i Arrays.sort(B) Arrays.sort Arrays B for (int i = 0; i < N; i++) {
                                System.out.print(B[i] + (i == N-1 ? "\n" : " "));
                        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
                                System.out.print(B[i] + (i == N-1 ? "\n" : " "));
                        } {
                                System.out.print(B[i] + (i == N-1 ? "\n" : " "));
                        } System.out.print(B[i] + (i == N-1 ? "\n" : " ")) System.out.print System.out System System.out B[i] + (i == N-1 ? "\n" : " ") B[i] B i (i == N-1 ? "\n" : " ") i == N-1 i N-1 N 1 "\n" " " System.out.println(bubbleSort(A, N)) System.out.println System.out System System.out bubbleSort(A, N) bubbleSort A N String args[] args private static int bubbleSort(int[] A, int N) {
                boolean flag = true;
                int ans = 0;
                while (flag) {
                        flag = false;
                        for (int j = N - 1; j >= 1; j--) {
                                if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                }
                        }
                }
                return ans;
        } bubbleSort {
                boolean flag = true;
                int ans = 0;
                while (flag) {
                        flag = false;
                        for (int j = N - 1; j >= 1; j--) {
                                if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                }
                        }
                }
                return ans;
        } boolean flag = true; flag true int ans = 0; ans 0 while (flag) {
                        flag = false;
                        for (int j = N - 1; j >= 1; j--) {
                                if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                }
                        }
                } flag {
                        flag = false;
                        for (int j = N - 1; j >= 1; j--) {
                                if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                }
                        }
                } flag = false flag false for (int j = N - 1; j >= 1; j--) {
                                if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                }
                        } int j = N - 1; int j = N - 1; j N - 1 N 1 j >= 1 j 1 j-- j-- j {
                                if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                }
                        } {
                                if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                }
                        } if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                } A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                } int tmp = A[j]; tmp A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = tmp A[j-1] A j-1 j 1 tmp flag = true flag true ans++ ans return ans; ans int[] A A int N N
import java.util.*;

class Main {
        public static void main(String args[]) {
                try (Scanner sc = new Scanner(System.in)) {
                        int N = sc.nextInt();
                        int[] A = new int[N];
                        int[] B = new int[N];

                        for (int i = 0; i < N; i++) {
                                A[i] = sc.nextInt();
                                B[i] = A[i];
                        }
                        Arrays.sort(B);
                        for (int i = 0; i < N; i++) {
                                System.out.print(B[i] + (i == N-1 ? "\n" : " "));
                        }
                        System.out.println(bubbleSort(A, N));
                }
        }
        private static int bubbleSort(int[] A, int N) {
                boolean flag = true;
                int ans = 0;
                while (flag) {
                        flag = false;
                        for (int j = N - 1; j >= 1; j--) {
                                if (A[j] < A[j-1]) {
                                        int tmp = A[j];
                                        A[j] = A[j-1];
                                        A[j-1] = tmp;
                                        flag = true;
                                        ans++;
                                }
                        }
                }
                return ans;
        }
}