import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            int[] bSort = new int[n];
            for(int i = 0;i < n;i++){
                bSort[i] = scan.nextInt();
            }
            int count = 0;
            for(int i = 0;i < n;i++){
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            }
            PrintOut(bSort,n);
            System.out.println(count);
        }
    }
     
    public static void swap(int[] a,int i,int j){
        int t = a[j];a[j] = a[i];a[i] = t;
    }
     
    public static void PrintOut(int[] a,int n){
        for(int i = 0;i < n;i++){
            System.out.print(a[i] + ((i == n-1)?"\n":" "));
        }
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            int[] bSort = new int[n];
            for(int i = 0;i < n;i++){
                bSort[i] = scan.nextInt();
            }
            int count = 0;
            for(int i = 0;i < n;i++){
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            }
            PrintOut(bSort,n);
            System.out.println(count);
        }
    }
     
    public static void swap(int[] a,int i,int j){
        int t = a[j];a[j] = a[i];a[i] = t;
    }
     
    public static void PrintOut(int[] a,int n){
        for(int i = 0;i < n;i++){
            System.out.print(a[i] + ((i == n-1)?"\n":" "));
        }
    }
} Main public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            int[] bSort = new int[n];
            for(int i = 0;i < n;i++){
                bSort[i] = scan.nextInt();
            }
            int count = 0;
            for(int i = 0;i < n;i++){
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            }
            PrintOut(bSort,n);
            System.out.println(count);
        }
    } main {
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            int[] bSort = new int[n];
            for(int i = 0;i < n;i++){
                bSort[i] = scan.nextInt();
            }
            int count = 0;
            for(int i = 0;i < n;i++){
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            }
            PrintOut(bSort,n);
            System.out.println(count);
        }
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) while(scan.hasNext()){
            int n = scan.nextInt();
            int[] bSort = new int[n];
            for(int i = 0;i < n;i++){
                bSort[i] = scan.nextInt();
            }
            int count = 0;
            for(int i = 0;i < n;i++){
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            }
            PrintOut(bSort,n);
            System.out.println(count);
        } scan.hasNext() scan.hasNext scan {
            int n = scan.nextInt();
            int[] bSort = new int[n];
            for(int i = 0;i < n;i++){
                bSort[i] = scan.nextInt();
            }
            int count = 0;
            for(int i = 0;i < n;i++){
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            }
            PrintOut(bSort,n);
            System.out.println(count);
        } int n = scan.nextInt(); n scan.nextInt() scan.nextInt scan int[] bSort = new int[n]; bSort new int[n] n for(int i = 0;i < n;i++){
                bSort[i] = scan.nextInt();
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                bSort[i] = scan.nextInt();
            } {
                bSort[i] = scan.nextInt();
            } bSort[i] = scan.nextInt() bSort[i] bSort i scan.nextInt() scan.nextInt scan int count = 0; count 0 for(int i = 0;i < n;i++){
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            } {
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            } for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                } int j = n-1; int j = n-1; j n-1 n 1 j > i j i j-- j-- j {
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                } {
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                } if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    } bSort[j] < bSort[j-1] bSort[j] bSort j bSort[j-1] bSort j-1 j 1 {
                        swap(bSort,j,j-1);
                        count++;
                    } swap(bSort,j,j-1) swap bSort j j-1 j 1 count++ count PrintOut(bSort,n) PrintOut bSort n System.out.println(count) System.out.println System.out System System.out count String[] args args public static void swap(int[] a,int i,int j){
        int t = a[j];a[j] = a[i];a[i] = t;
    } swap {
        int t = a[j];a[j] = a[i];a[i] = t;
    } int t = a[j]; t a[j] a j a[j] = a[i] a[j] a j a[i] a i a[i] = t a[i] a i t int[] a a int i i int j j public static void PrintOut(int[] a,int n){
        for(int i = 0;i < n;i++){
            System.out.print(a[i] + ((i == n-1)?"\n":" "));
        }
    } PrintOut {
        for(int i = 0;i < n;i++){
            System.out.print(a[i] + ((i == n-1)?"\n":" "));
        }
    } for(int i = 0;i < n;i++){
            System.out.print(a[i] + ((i == n-1)?"\n":" "));
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            System.out.print(a[i] + ((i == n-1)?"\n":" "));
        } {
            System.out.print(a[i] + ((i == n-1)?"\n":" "));
        } System.out.print(a[i] + ((i == n-1)?"\n":" ")) System.out.print System.out System System.out a[i] + ((i == n-1)?"\n":" ") a[i] a i ((i == n-1)?"\n":" ") (i == n-1) i n-1 n 1 "\n" " " int[] a a int n n public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            int[] bSort = new int[n];
            for(int i = 0;i < n;i++){
                bSort[i] = scan.nextInt();
            }
            int count = 0;
            for(int i = 0;i < n;i++){
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            }
            PrintOut(bSort,n);
            System.out.println(count);
        }
    }
     
    public static void swap(int[] a,int i,int j){
        int t = a[j];a[j] = a[i];a[i] = t;
    }
     
    public static void PrintOut(int[] a,int n){
        for(int i = 0;i < n;i++){
            System.out.print(a[i] + ((i == n-1)?"\n":" "));
        }
    }
} public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            int[] bSort = new int[n];
            for(int i = 0;i < n;i++){
                bSort[i] = scan.nextInt();
            }
            int count = 0;
            for(int i = 0;i < n;i++){
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            }
            PrintOut(bSort,n);
            System.out.println(count);
        }
    }
     
    public static void swap(int[] a,int i,int j){
        int t = a[j];a[j] = a[i];a[i] = t;
    }
     
    public static void PrintOut(int[] a,int n){
        for(int i = 0;i < n;i++){
            System.out.print(a[i] + ((i == n-1)?"\n":" "));
        }
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            int n = scan.nextInt();
            int[] bSort = new int[n];
            for(int i = 0;i < n;i++){
                bSort[i] = scan.nextInt();
            }
            int count = 0;
            for(int i = 0;i < n;i++){
                for(int j = n-1;j > i;j--){
                    if(bSort[j] < bSort[j-1]){
                        swap(bSort,j,j-1);
                        count++;
                    }
                }
            }
            PrintOut(bSort,n);
            System.out.println(count);
        }
    }
     
    public static void swap(int[] a,int i,int j){
        int t = a[j];a[j] = a[i];a[i] = t;
    }
     
    public static void PrintOut(int[] a,int n){
        for(int i = 0;i < n;i++){
            System.out.print(a[i] + ((i == n-1)?"\n":" "));
        }
    }
}