import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n;
    static int a[];
    static int count = 0;

    public static void main(String[] args) {
        read();
        solve();
        output();
    }

    public static void read() {
        n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
    }

    public static void solve() {
        boolean flag= true;
        while(flag) {
        flag = false;
            for (int i = n-1; i > 0; i--) {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            }
        }
    }

    public static void output() {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]);
            if (i + 1 < a.length) {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n;
    static int a[];
    static int count = 0;

    public static void main(String[] args) {
        read();
        solve();
        output();
    }

    public static void read() {
        n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
    }

    public static void solve() {
        boolean flag= true;
        while(flag) {
        flag = false;
            for (int i = n-1; i > 0; i--) {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            }
        }
    }

    public static void output() {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]);
            if (i + 1 < a.length) {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(count);
    }
} Main static Scanner sc = new Scanner(System.in); sc new Scanner(System.in) static int n; n static int a[]; a static int count = 0; count 0 public static void main(String[] args) {
        read();
        solve();
        output();
    } main {
        read();
        solve();
        output();
    } read() read solve() solve output() output String[] args args public static void read() {
        n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
    } read {
        n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
    } n = sc.nextInt() n sc.nextInt() sc.nextInt sc 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 public static void solve() {
        boolean flag= true;
        while(flag) {
        flag = false;
            for (int i = n-1; i > 0; i--) {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            }
        }
    } solve {
        boolean flag= true;
        while(flag) {
        flag = false;
            for (int i = n-1; i > 0; i--) {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            }
        }
    } boolean flag= true; flag true while(flag) {
        flag = false;
            for (int i = n-1; i > 0; i--) {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            }
        } flag {
        flag = false;
            for (int i = n-1; i > 0; i--) {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            }
        } flag = false flag false for (int i = n-1; i > 0; i--) {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            } int i = n-1; int i = n-1; i n-1 n 1 i > 0 i 0 i-- i-- i {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            } {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            } if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                } a[i - 1] > a[i] a[i - 1] a i - 1 i 1 a[i] a i {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                } int tmp = a[i]; tmp a[i] a i a[i] = a[i - 1] a[i] a i a[i - 1] a i - 1 i 1 a[i - 1] = tmp a[i - 1] a i - 1 i 1 tmp flag = true flag true count++ count public static void output() {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]);
            if (i + 1 < a.length) {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(count);
    } output {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]);
            if (i + 1 < a.length) {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(count);
    } for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]);
            if (i + 1 < a.length) {
                System.out.print(" ");
            }
        } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
            System.out.print(a[i]);
            if (i + 1 < a.length) {
                System.out.print(" ");
            }
        } {
            System.out.print(a[i]);
            if (i + 1 < a.length) {
                System.out.print(" ");
            }
        } System.out.print(a[i]) System.out.print System.out System System.out a[i] a i if (i + 1 < a.length) {
                System.out.print(" ");
            } i + 1 < a.length i + 1 i 1 a.length a a.length {
                System.out.print(" ");
            } System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out System.out.println(count) System.out.println System.out System System.out count public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n;
    static int a[];
    static int count = 0;

    public static void main(String[] args) {
        read();
        solve();
        output();
    }

    public static void read() {
        n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
    }

    public static void solve() {
        boolean flag= true;
        while(flag) {
        flag = false;
            for (int i = n-1; i > 0; i--) {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            }
        }
    }

    public static void output() {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]);
            if (i + 1 < a.length) {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(count);
    }
} public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n;
    static int a[];
    static int count = 0;

    public static void main(String[] args) {
        read();
        solve();
        output();
    }

    public static void read() {
        n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
    }

    public static void solve() {
        boolean flag= true;
        while(flag) {
        flag = false;
            for (int i = n-1; i > 0; i--) {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            }
        }
    }

    public static void output() {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]);
            if (i + 1 < a.length) {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(count);
    }
} Main
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static int n;
    static int a[];
    static int count = 0;

    public static void main(String[] args) {
        read();
        solve();
        output();
    }

    public static void read() {
        n = sc.nextInt();
        a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
    }

    public static void solve() {
        boolean flag= true;
        while(flag) {
        flag = false;
            for (int i = n-1; i > 0; i--) {
                if (a[i - 1] > a[i]) {
                    int tmp = a[i];
                    a[i] = a[i - 1];
                    a[i - 1] = tmp;
                    flag = true;
                    count++;
                }
            }
        }
    }

    public static void output() {
        for (int i = 0; i < a.length; i++) {
            System.out.print(a[i]);
            if (i + 1 < a.length) {
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(count);
    }
}