import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        int i;
        int j;
        int count=0;
        for(i=0;i<n;i++){
            num[i]=sc.nextInt();
        }
        for(int k=0;k<n;k++) {
            for (j = n - 1; j > 0; j--) {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            }
        }
        for(i=0;i<n;i++) {
            if(i==n-1) System.out.println(num[i]);
            else System.out.printf("%d ",num[i]);

        }
        System.out.println(count);
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        int i;
        int j;
        int count=0;
        for(i=0;i<n;i++){
            num[i]=sc.nextInt();
        }
        for(int k=0;k<n;k++) {
            for (j = n - 1; j > 0; j--) {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            }
        }
        for(i=0;i<n;i++) {
            if(i==n-1) System.out.println(num[i]);
            else System.out.printf("%d ",num[i]);

        }
        System.out.println(count);
    }
} Main public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        int i;
        int j;
        int count=0;
        for(i=0;i<n;i++){
            num[i]=sc.nextInt();
        }
        for(int k=0;k<n;k++) {
            for (j = n - 1; j > 0; j--) {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            }
        }
        for(i=0;i<n;i++) {
            if(i==n-1) System.out.println(num[i]);
            else System.out.printf("%d ",num[i]);

        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        int i;
        int j;
        int count=0;
        for(i=0;i<n;i++){
            num[i]=sc.nextInt();
        }
        for(int k=0;k<n;k++) {
            for (j = n - 1; j > 0; j--) {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            }
        }
        for(i=0;i<n;i++) {
            if(i==n-1) System.out.println(num[i]);
            else System.out.printf("%d ",num[i]);

        }
        System.out.println(count);
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int[] num = new int[n]; num new int[n] n int i; i int j; j int count=0; count 0 for(i=0;i<n;i++){
            num[i]=sc.nextInt();
        } i=0; i=0 i 0 i<n i n i++ i++ i {
            num[i]=sc.nextInt();
        } {
            num[i]=sc.nextInt();
        } num[i]=sc.nextInt() num[i] num i sc.nextInt() sc.nextInt sc for(int k=0;k<n;k++) {
            for (j = n - 1; j > 0; j--) {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            }
        } int k=0; int k=0; k 0 k<n k n k++ k++ k {
            for (j = n - 1; j > 0; j--) {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            }
        } {
            for (j = n - 1; j > 0; j--) {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            }
        } for (j = n - 1; j > 0; j--) {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            } j = n - 1; j = n - 1 j n - 1 n 1 j > 0 j 0 j-- j-- j {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            } {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            } if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    } num[j]<num[j-1] num[j] num j num[j-1] num j-1 j 1 {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    } int a = num[j]; a num[j] num j num[j] = num[j - 1] num[j] num j num[j - 1] num j - 1 j 1 num[j - 1] = a num[j - 1] num j - 1 j 1 a count=count+1 count count+1 count 1 for(i=0;i<n;i++) {
            if(i==n-1) System.out.println(num[i]);
            else System.out.printf("%d ",num[i]);

        } i=0; i=0 i 0 i<n i n i++ i++ i {
            if(i==n-1) System.out.println(num[i]);
            else System.out.printf("%d ",num[i]);

        } {
            if(i==n-1) System.out.println(num[i]);
            else System.out.printf("%d ",num[i]);

        } if(i==n-1) System.out.println(num[i]);
            else System.out.printf("%d ",num[i]); i==n-1 i n-1 n 1 System.out.println(num[i]) System.out.println System.out System System.out num[i] num i System.out.printf("%d ",num[i]) System.out.printf System.out System System.out "%d " num[i] num i 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 sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        int i;
        int j;
        int count=0;
        for(i=0;i<n;i++){
            num[i]=sc.nextInt();
        }
        for(int k=0;k<n;k++) {
            for (j = n - 1; j > 0; j--) {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            }
        }
        for(i=0;i<n;i++) {
            if(i==n-1) System.out.println(num[i]);
            else System.out.printf("%d ",num[i]);

        }
        System.out.println(count);
    }
} public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        int i;
        int j;
        int count=0;
        for(i=0;i<n;i++){
            num[i]=sc.nextInt();
        }
        for(int k=0;k<n;k++) {
            for (j = n - 1; j > 0; j--) {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            }
        }
        for(i=0;i<n;i++) {
            if(i==n-1) System.out.println(num[i]);
            else System.out.printf("%d ",num[i]);

        }
        System.out.println(count);
    }
} Main
import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] num = new int[n];
        int i;
        int j;
        int count=0;
        for(i=0;i<n;i++){
            num[i]=sc.nextInt();
        }
        for(int k=0;k<n;k++) {
            for (j = n - 1; j > 0; j--) {

                    if(num[j]<num[j-1]) {
                        int a = num[j];
                        num[j] = num[j - 1];
                        num[j - 1] = a;
                        count=count+1;
                    }
            }
        }
        for(i=0;i<n;i++) {
            if(i==n-1) System.out.println(num[i]);
            else System.out.printf("%d ",num[i]);

        }
        System.out.println(count);
    }
}
