import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        boolean flag = true;
        while(flag){
            flag = false;
            for(int j = n-1; j > 0; j--){
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            }
        }
        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(ans);
    }
}
 import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        boolean flag = true;
        while(flag){
            flag = false;
            for(int j = n-1; j > 0; j--){
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            }
        }
        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(ans);
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        boolean flag = true;
        while(flag){
            flag = false;
            for(int j = n-1; j > 0; j--){
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            }
        }
        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(ans);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        boolean flag = true;
        while(flag){
            flag = false;
            for(int j = n-1; j > 0; j--){
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            }
        }
        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(ans);
    } Scanner 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 int ans = 0; ans 0 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 while(flag){
            flag = false;
            for(int j = n-1; j > 0; j--){
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            }
        } flag {
            flag = false;
            for(int j = n-1; j > 0; j--){
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            }
        } flag = false flag false for(int j = n-1; j > 0; j--){
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            } int j = n-1; int j = n-1; j n-1 n 1 j > 0 j 0 j-- j-- j {
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            } {
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            } if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                } a[j] < a[j-1] a[j] a j a[j-1] a j-1 j 1 {
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                } int work = a[j]; work a[j] a j a[j] = a[j-1] a[j] a j a[j-1] a j-1 j 1 a[j-1] = work a[j-1] a j-1 j 1 work ans ++ ans flag =true flag true for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        } int i = 0; int i = 0; i 0 i < n-1 i n-1 n 1 i++ i++ i {
            System.out.print(a[i] + " ");
        } {
            System.out.print(a[i] + " ");
        } System.out.print(a[i] + " ") System.out.print System.out System System.out a[i] + " " a[i] a i " " System.out.println(a[n-1]) System.out.println System.out System System.out a[n-1] a n-1 n 1 System.out.println(ans) System.out.println System.out System System.out ans String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        boolean flag = true;
        while(flag){
            flag = false;
            for(int j = n-1; j > 0; j--){
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            }
        }
        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(ans);
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        boolean flag = true;
        while(flag){
            flag = false;
            for(int j = n-1; j > 0; j--){
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            }
        }
        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(ans);
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        int ans = 0;
        for(int i = 0; i < n; i++){
            a[i] = sc.nextInt();
        }
        boolean flag = true;
        while(flag){
            flag = false;
            for(int j = n-1; j > 0; j--){
                if(a[j] < a[j-1]){
                    int work = a[j];
                    a[j] = a[j-1];
                    a[j-1] = work;
                    ans ++;
                    flag =true;
                }
            }
        }
        for(int i = 0; i < n-1; i++){
            System.out.print(a[i] + " ");
        }
        System.out.println(a[n-1]);
        System.out.println(ans);
    }
}

