import java.util.Scanner;

public class Main{
public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int A[] = new int[100];

        for(int i=0;i<n;i++){
            A[i] = scan.nextInt();
        }
        int count = 0;
        boolean flag = true;
        while(flag){
            flag = false;
            for(int i=n-1;i>=1;i--){
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            }
        }
        printArray(A, n);
        System.out.println(count);
    }

    // スペース区切りで表示
    public static void printArray(int A[], int n){
        int i;
        for(i=0;i<n-1;i++){
            System.out.print(A[i] + " ");
        }
        System.out.println(A[i]);
    }
} import java.util.Scanner; Scanner java.util public class Main{
public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int A[] = new int[100];

        for(int i=0;i<n;i++){
            A[i] = scan.nextInt();
        }
        int count = 0;
        boolean flag = true;
        while(flag){
            flag = false;
            for(int i=n-1;i>=1;i--){
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            }
        }
        printArray(A, n);
        System.out.println(count);
    }

    // スペース区切りで表示
    public static void printArray(int A[], int n){
        int i;
        for(i=0;i<n-1;i++){
            System.out.print(A[i] + " ");
        }
        System.out.println(A[i]);
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int A[] = new int[100];

        for(int i=0;i<n;i++){
            A[i] = scan.nextInt();
        }
        int count = 0;
        boolean flag = true;
        while(flag){
            flag = false;
            for(int i=n-1;i>=1;i--){
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            }
        }
        printArray(A, n);
        System.out.println(count);
    } main {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int A[] = new int[100];

        for(int i=0;i<n;i++){
            A[i] = scan.nextInt();
        }
        int count = 0;
        boolean flag = true;
        while(flag){
            flag = false;
            for(int i=n-1;i>=1;i--){
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            }
        }
        printArray(A, n);
        System.out.println(count);
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int A[] = new int[100]; A new int[100] 100 for(int i=0;i<n;i++){
            A[i] = scan.nextInt();
        } int i=0; int i=0; i 0 i<n i n i++ i++ i {
            A[i] = scan.nextInt();
        } {
            A[i] = scan.nextInt();
        } A[i] = scan.nextInt() A[i] A i scan.nextInt() scan.nextInt scan int count = 0; count 0 boolean flag = true; flag true while(flag){
            flag = false;
            for(int i=n-1;i>=1;i--){
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            }
        } flag {
            flag = false;
            for(int i=n-1;i>=1;i--){
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            }
        } flag = false flag false for(int i=n-1;i>=1;i--){
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            } int i=n-1; int i=n-1; i n-1 n 1 i>=1 i 1 i-- i-- i {
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            } {
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            } if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                } A[i] < A[i-1] A[i] A i A[i-1] A i-1 i 1 {
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                } count++ 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 printArray(A, n) printArray A n System.out.println(count) System.out.println System.out System System.out count String[] args args // スペース区切りで表示
    public static void printArray(int A[], int n){
        int i;
        for(i=0;i<n-1;i++){
            System.out.print(A[i] + " ");
        }
        System.out.println(A[i]);
    } printArray {
        int i;
        for(i=0;i<n-1;i++){
            System.out.print(A[i] + " ");
        }
        System.out.println(A[i]);
    } int i; i for(i=0;i<n-1;i++){
            System.out.print(A[i] + " ");
        } i=0; 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[i]) System.out.println System.out System System.out A[i] A i int A[] A int n n public class Main{
public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int A[] = new int[100];

        for(int i=0;i<n;i++){
            A[i] = scan.nextInt();
        }
        int count = 0;
        boolean flag = true;
        while(flag){
            flag = false;
            for(int i=n-1;i>=1;i--){
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            }
        }
        printArray(A, n);
        System.out.println(count);
    }

    // スペース区切りで表示
    public static void printArray(int A[], int n){
        int i;
        for(i=0;i<n-1;i++){
            System.out.print(A[i] + " ");
        }
        System.out.println(A[i]);
    }
} public class Main{
public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int A[] = new int[100];

        for(int i=0;i<n;i++){
            A[i] = scan.nextInt();
        }
        int count = 0;
        boolean flag = true;
        while(flag){
            flag = false;
            for(int i=n-1;i>=1;i--){
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            }
        }
        printArray(A, n);
        System.out.println(count);
    }

    // スペース区切りで表示
    public static void printArray(int A[], int n){
        int i;
        for(i=0;i<n-1;i++){
            System.out.print(A[i] + " ");
        }
        System.out.println(A[i]);
    }
} Main
import java.util.Scanner;

public class Main{
public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int A[] = new int[100];

        for(int i=0;i<n;i++){
            A[i] = scan.nextInt();
        }
        int count = 0;
        boolean flag = true;
        while(flag){
            flag = false;
            for(int i=n-1;i>=1;i--){
                if(A[i] < A[i-1]){
                    count++;
                    // 要素の交換
                    int tmp = A[i];
                    A[i] = A[i-1];
                    A[i-1] = tmp;
                    flag = true;
                }
            }
        }
        printArray(A, n);
        System.out.println(count);
    }

    // スペース区切りで表示
    public static void printArray(int A[], int n){
        int i;
        for(i=0;i<n-1;i++){
            System.out.print(A[i] + " ");
        }
        System.out.println(A[i]);
    }
}