import java.util.Scanner;

public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int count=0;
        for(int s=0;s<N-1;s++){
            for(int j=N-1;j>s;j--){
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            }
        }
        for(int k=0;k<N;k++){
            if(k==N-1){
                System.out.printf("%d",A[k]);
            }else{
                System.out.printf("%d ",A[k]);
            }
        }
        System.out.printf("\n");
        System.out.println(count);
        }
    }
 import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int count=0;
        for(int s=0;s<N-1;s++){
            for(int j=N-1;j>s;j--){
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            }
        }
        for(int k=0;k<N;k++){
            if(k==N-1){
                System.out.printf("%d",A[k]);
            }else{
                System.out.printf("%d ",A[k]);
            }
        }
        System.out.printf("\n");
        System.out.println(count);
        }
    } Main public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int count=0;
        for(int s=0;s<N-1;s++){
            for(int j=N-1;j>s;j--){
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            }
        }
        for(int k=0;k<N;k++){
            if(k==N-1){
                System.out.printf("%d",A[k]);
            }else{
                System.out.printf("%d ",A[k]);
            }
        }
        System.out.printf("\n");
        System.out.println(count);
        } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int count=0;
        for(int s=0;s<N-1;s++){
            for(int j=N-1;j>s;j--){
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            }
        }
        for(int k=0;k<N;k++){
            if(k==N-1){
                System.out.printf("%d",A[k]);
            }else{
                System.out.printf("%d ",A[k]);
            }
        }
        System.out.printf("\n");
        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[] A = new int[N]; A new int[N] N for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            A[i] = sc.nextInt();
        } {
            A[i] = sc.nextInt();
        } A[i] = sc.nextInt() A[i] A i sc.nextInt() sc.nextInt sc int count=0; count 0 for(int s=0;s<N-1;s++){
            for(int j=N-1;j>s;j--){
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            }
        } int s=0; int s=0; s 0 s<N-1 s N-1 N 1 s++ s++ s {
            for(int j=N-1;j>s;j--){
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            }
        } {
            for(int j=N-1;j>s;j--){
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            }
        } for(int j=N-1;j>s;j--){
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            } int j=N-1; int j=N-1; j N-1 N 1 j>s j s j-- j-- j {
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            } {
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            } if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                } A[j]<A[j-1] A[j] A j A[j-1] A j-1 j 1 {
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                } int x = A[j]; x A[j] A j A[j]=A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1]=x A[j-1] A j-1 j 1 x count++ count for(int k=0;k<N;k++){
            if(k==N-1){
                System.out.printf("%d",A[k]);
            }else{
                System.out.printf("%d ",A[k]);
            }
        } int k=0; int k=0; k 0 k<N k N k++ k++ k {
            if(k==N-1){
                System.out.printf("%d",A[k]);
            }else{
                System.out.printf("%d ",A[k]);
            }
        } {
            if(k==N-1){
                System.out.printf("%d",A[k]);
            }else{
                System.out.printf("%d ",A[k]);
            }
        } if(k==N-1){
                System.out.printf("%d",A[k]);
            }else{
                System.out.printf("%d ",A[k]);
            } k==N-1 k N-1 N 1 {
                System.out.printf("%d",A[k]);
            } System.out.printf("%d",A[k]) System.out.printf System.out System System.out "%d" A[k] A k {
                System.out.printf("%d ",A[k]);
            } System.out.printf("%d ",A[k]) System.out.printf System.out System System.out "%d " A[k] A k System.out.printf("\n") System.out.printf System.out System System.out "\n" System.out.println(count) System.out.println System.out System System.out count String[]argc argc public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int count=0;
        for(int s=0;s<N-1;s++){
            for(int j=N-1;j>s;j--){
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            }
        }
        for(int k=0;k<N;k++){
            if(k==N-1){
                System.out.printf("%d",A[k]);
            }else{
                System.out.printf("%d ",A[k]);
            }
        }
        System.out.printf("\n");
        System.out.println(count);
        }
    } public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int count=0;
        for(int s=0;s<N-1;s++){
            for(int j=N-1;j>s;j--){
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            }
        }
        for(int k=0;k<N;k++){
            if(k==N-1){
                System.out.printf("%d",A[k]);
            }else{
                System.out.printf("%d ",A[k]);
            }
        }
        System.out.printf("\n");
        System.out.println(count);
        }
    } Main
import java.util.Scanner;

public class Main{
    public static void main(String[]argc){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] A = new int[N];
        for(int i=0;i<N;i++){
            A[i] = sc.nextInt();
        }
        int count=0;
        for(int s=0;s<N-1;s++){
            for(int j=N-1;j>s;j--){
                if(A[j]<A[j-1]){
                    int x = A[j];
                    A[j]=A[j-1];
                    A[j-1]=x;
                    count++;
                }
            }
        }
        for(int k=0;k<N;k++){
            if(k==N-1){
                System.out.printf("%d",A[k]);
            }else{
                System.out.printf("%d ",A[k]);
            }
        }
        System.out.printf("\n");
        System.out.println(count);
        }
    }

