import java.util.*;

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

public class Main{
    public static void main(String[] args){
        Scanner a = new Scanner(System.in);
        int n = a.nextInt();
        int A[] = new int[n];
        for(int i=0; i<n; i++){
            A[i] = a.nextInt();
        }
        int flag = 1;
        int count = 0;
        while(flag==1){
            flag = 0;
            for(int i=n-1; i>=1; i--){
                if(A[i] < A[i-1]){
                    A[i] = A[i] + A[i-1];
                    A[i-1] = A[i] - A[i-1];
                    A[i]= A[i] - A[i-1];
                    flag = 1;
                    count++;
                }
            }       
        }
        for(int i=0; i<n; i++){
            System.out.print(A[i]);
            if(i<n-1){
                System.out.print(" ");
            }
        }
        System.out.println();
        System.out.println(count);
    }
}
