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

public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) a[i] = input.nextInt();
        int swaps = 0;
        for (int i = 0; i < n; ++i) {
            for (int k = n - 1; k > i; --k) {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            }
        }
        System.out.print(a[0]);
        for (int i = 1; i < n; ++i) System.out.print(" " + a[i]);
        System.out.println("");                
        System.out.println(swaps);
    }            
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) a[i] = input.nextInt();
        int swaps = 0;
        for (int i = 0; i < n; ++i) {
            for (int k = n - 1; k > i; --k) {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            }
        }
        System.out.print(a[0]);
        for (int i = 1; i < n; ++i) System.out.print(" " + a[i]);
        System.out.println("");                
        System.out.println(swaps);
    }            
} Main static final int INF = 1000000000; INF 1000000000 public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) a[i] = input.nextInt();
        int swaps = 0;
        for (int i = 0; i < n; ++i) {
            for (int k = n - 1; k > i; --k) {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            }
        }
        System.out.print(a[0]);
        for (int i = 1; i < n; ++i) System.out.print(" " + a[i]);
        System.out.println("");                
        System.out.println(swaps);
    } main {                
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) a[i] = input.nextInt();
        int swaps = 0;
        for (int i = 0; i < n; ++i) {
            for (int k = n - 1; k > i; --k) {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            }
        }
        System.out.print(a[0]);
        for (int i = 1; i < n; ++i) System.out.print(" " + a[i]);
        System.out.println("");                
        System.out.println(swaps);
    } Scanner input = new Scanner(System.in); input new Scanner(System.in) int n = input.nextInt(); n input.nextInt() input.nextInt input int[] a = new int[n]; a new int[n] n for (int i = 0; i < n; ++i) a[i] = input.nextInt(); int i = 0; int i = 0; i 0 i < n i n ++i ++i i a[i] = input.nextInt(); a[i] = input.nextInt() a[i] a i input.nextInt() input.nextInt input int swaps = 0; swaps 0 for (int i = 0; i < n; ++i) {
            for (int k = n - 1; k > i; --k) {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            }
        } int i = 0; int i = 0; i 0 i < n i n ++i ++i i {
            for (int k = n - 1; k > i; --k) {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            }
        } {
            for (int k = n - 1; k > i; --k) {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            }
        } for (int k = n - 1; k > i; --k) {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            } int k = n - 1; int k = n - 1; k n - 1 n 1 k > i k i --k --k k {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            } {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            } if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                } a[k] < a[k - 1] a[k] a k a[k - 1] a k - 1 k 1 {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                } int temp = a[k]; temp a[k] a k a[k] = a[k - 1] a[k] a k a[k - 1] a k - 1 k 1 a[k - 1] = temp a[k - 1] a k - 1 k 1 temp ++swaps swaps System.out.print(a[0]) System.out.print System.out System System.out a[0] a 0 for (int i = 1; i < n; ++i) System.out.print(" " + a[i]); int i = 1; int i = 1; i 1 i < n i n ++i ++i 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("") System.out.println System.out System System.out "" System.out.println(swaps) System.out.println System.out System System.out swaps String[] args args public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) a[i] = input.nextInt();
        int swaps = 0;
        for (int i = 0; i < n; ++i) {
            for (int k = n - 1; k > i; --k) {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            }
        }
        System.out.print(a[0]);
        for (int i = 1; i < n; ++i) System.out.print(" " + a[i]);
        System.out.println("");                
        System.out.println(swaps);
    }            
} public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) a[i] = input.nextInt();
        int swaps = 0;
        for (int i = 0; i < n; ++i) {
            for (int k = n - 1; k > i; --k) {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            }
        }
        System.out.print(a[0]);
        for (int i = 1; i < n; ++i) System.out.print(" " + a[i]);
        System.out.println("");                
        System.out.println(swaps);
    }            
} Main
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    static final int INF = 1000000000;     
    
    public static void main(String[] args) throws Exception {                
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; ++i) a[i] = input.nextInt();
        int swaps = 0;
        for (int i = 0; i < n; ++i) {
            for (int k = n - 1; k > i; --k) {
                if (a[k] < a[k - 1]) {
                    int temp = a[k];
                    a[k] = a[k - 1];
                    a[k - 1] = temp;
                    ++swaps;
                }
            }
        }
        System.out.print(a[0]);
        for (int i = 1; i < n; ++i) System.out.print(" " + a[i]);
        System.out.println("");                
        System.out.println(swaps);
    }            
}