import java.util.Scanner;

public class Main {

    public Main() {
    }

    public static void main(String[] args) {
        new Main().solve();
    }

    private Scanner sc;

    private void solve() {
        sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        boolean flag = true;
        int cnt = 0;
        int i = 0;
        while (flag) {
            flag = false;
            for (int j = N - 1; j >= i + 1; j--) {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            }
            i++;
        }

        String ans = "";
        for (int num : A) {
            ans += num;
            ans += " ";
        }
        System.out.println(ans.trim());
        System.out.println(cnt);
    }

} import java.util.Scanner; Scanner java.util public class Main {

    public Main() {
    }

    public static void main(String[] args) {
        new Main().solve();
    }

    private Scanner sc;

    private void solve() {
        sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        boolean flag = true;
        int cnt = 0;
        int i = 0;
        while (flag) {
            flag = false;
            for (int j = N - 1; j >= i + 1; j--) {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            }
            i++;
        }

        String ans = "";
        for (int num : A) {
            ans += num;
            ans += " ";
        }
        System.out.println(ans.trim());
        System.out.println(cnt);
    }

} Main private Scanner sc; sc public Main() {
    } Main {
    } public static void main(String[] args) {
        new Main().solve();
    } main {
        new Main().solve();
    } new Main().solve() new Main().solve new Main() String[] args args private void solve() {
        sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        boolean flag = true;
        int cnt = 0;
        int i = 0;
        while (flag) {
            flag = false;
            for (int j = N - 1; j >= i + 1; j--) {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            }
            i++;
        }

        String ans = "";
        for (int num : A) {
            ans += num;
            ans += " ";
        }
        System.out.println(ans.trim());
        System.out.println(cnt);
    } solve {
        sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        boolean flag = true;
        int cnt = 0;
        int i = 0;
        while (flag) {
            flag = false;
            for (int j = N - 1; j >= i + 1; j--) {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            }
            i++;
        }

        String ans = "";
        for (int num : A) {
            ans += num;
            ans += " ";
        }
        System.out.println(ans.trim());
        System.out.println(cnt);
    } sc = new Scanner(System.in) sc new Scanner(System.in) int N = sc.nextInt(); N sc.nextInt() sc.nextInt sc int[] A = new int[N]; A new int[N] N for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < N i N i++ i++ i {
            A[i] = sc.nextInt();
        } {
            A[i] = sc.nextInt();
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc boolean flag = true; flag true int cnt = 0; cnt 0 int i = 0; i 0 while (flag) {
            flag = false;
            for (int j = N - 1; j >= i + 1; j--) {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            }
            i++;
        } flag {
            flag = false;
            for (int j = N - 1; j >= i + 1; j--) {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            }
            i++;
        } flag = false flag false for (int j = N - 1; j >= i + 1; j--) {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            } int j = N - 1; int j = N - 1; j N - 1 N 1 j >= i + 1 j i + 1 i 1 j-- j-- j {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            } {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            } if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                } A[j] < A[j - 1] A[j] A j A[j - 1] A j - 1 j 1 {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                } int tmp = A[j - 1]; tmp A[j - 1] A j - 1 j 1 A[j - 1] = A[j] A[j - 1] A j - 1 j 1 A[j] A j A[j] = tmp A[j] A j tmp flag = true flag true cnt++ cnt i++ i String ans = ""; ans "" for (int num : A) {
            ans += num;
            ans += " ";
        } int num A {
            ans += num;
            ans += " ";
        } {
            ans += num;
            ans += " ";
        } ans += num ans num ans += " " ans " " System.out.println(ans.trim()) System.out.println System.out System System.out ans.trim() ans.trim ans System.out.println(cnt) System.out.println System.out System System.out cnt public class Main {

    public Main() {
    }

    public static void main(String[] args) {
        new Main().solve();
    }

    private Scanner sc;

    private void solve() {
        sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        boolean flag = true;
        int cnt = 0;
        int i = 0;
        while (flag) {
            flag = false;
            for (int j = N - 1; j >= i + 1; j--) {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            }
            i++;
        }

        String ans = "";
        for (int num : A) {
            ans += num;
            ans += " ";
        }
        System.out.println(ans.trim());
        System.out.println(cnt);
    }

} public class Main {

    public Main() {
    }

    public static void main(String[] args) {
        new Main().solve();
    }

    private Scanner sc;

    private void solve() {
        sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        boolean flag = true;
        int cnt = 0;
        int i = 0;
        while (flag) {
            flag = false;
            for (int j = N - 1; j >= i + 1; j--) {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            }
            i++;
        }

        String ans = "";
        for (int num : A) {
            ans += num;
            ans += " ";
        }
        System.out.println(ans.trim());
        System.out.println(cnt);
    }

} Main
import java.util.Scanner;

public class Main {

    public Main() {
    }

    public static void main(String[] args) {
        new Main().solve();
    }

    private Scanner sc;

    private void solve() {
        sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        boolean flag = true;
        int cnt = 0;
        int i = 0;
        while (flag) {
            flag = false;
            for (int j = N - 1; j >= i + 1; j--) {
                if (A[j] < A[j - 1]) {
                    int tmp = A[j - 1];
                    A[j - 1] = A[j];
                    A[j] = tmp;
                    flag = true;
                    cnt++;
                }
            }
            i++;
        }

        String ans = "";
        for (int num : A) {
            ans += num;
            ans += " ";
        }
        System.out.println(ans.trim());
        System.out.println(cnt);
    }

}