
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int bigger ;
        int a[] = new int[N];
        int i,j,k,x ;
        int count =0;
        for (x =0 ; x < N ; x++){
            a[x] = sc.nextInt();
        }
        for (i = 0; a.length > i;i++ ){
            for(j=N-1;j>=i+1;j--){
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            }
        }
        for(k=0; k<N-1;k++){
            System.out.print(a[k]+ " ");
        }
        if(k == N-1){
            System.out.println(a[k]);
        }
        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 bigger ;
        int a[] = new int[N];
        int i,j,k,x ;
        int count =0;
        for (x =0 ; x < N ; x++){
            a[x] = sc.nextInt();
        }
        for (i = 0; a.length > i;i++ ){
            for(j=N-1;j>=i+1;j--){
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            }
        }
        for(k=0; k<N-1;k++){
            System.out.print(a[k]+ " ");
        }
        if(k == N-1){
            System.out.println(a[k]);
        }
        System.out.println(count);
    }

} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int bigger ;
        int a[] = new int[N];
        int i,j,k,x ;
        int count =0;
        for (x =0 ; x < N ; x++){
            a[x] = sc.nextInt();
        }
        for (i = 0; a.length > i;i++ ){
            for(j=N-1;j>=i+1;j--){
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            }
        }
        for(k=0; k<N-1;k++){
            System.out.print(a[k]+ " ");
        }
        if(k == N-1){
            System.out.println(a[k]);
        }
        System.out.println(count);
    } main {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int bigger ;
        int a[] = new int[N];
        int i,j,k,x ;
        int count =0;
        for (x =0 ; x < N ; x++){
            a[x] = sc.nextInt();
        }
        for (i = 0; a.length > i;i++ ){
            for(j=N-1;j>=i+1;j--){
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            }
        }
        for(k=0; k<N-1;k++){
            System.out.print(a[k]+ " ");
        }
        if(k == N-1){
            System.out.println(a[k]);
        }
        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 bigger ; bigger int a[] = new int[N]; a new int[N] N int i i j j k k x ; x int count =0; count 0 for (x =0 ; x < N ; x++){
            a[x] = sc.nextInt();
        } x =0 ; x =0 x 0 x < N x N x++ x++ x {
            a[x] = sc.nextInt();
        } {
            a[x] = sc.nextInt();
        } a[x] = sc.nextInt() a[x] a x sc.nextInt() sc.nextInt sc for (i = 0; a.length > i;i++ ){
            for(j=N-1;j>=i+1;j--){
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            }
        } i = 0; i = 0 i 0 a.length > i a.length a a.length i i++ i++ i {
            for(j=N-1;j>=i+1;j--){
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            }
        } {
            for(j=N-1;j>=i+1;j--){
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            }
        } for(j=N-1;j>=i+1;j--){
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            } j=N-1; j=N-1 j N-1 N 1 j>=i+1 j i+1 i 1 j-- j-- j {
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            } {
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            } if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                } a[j] <a[j-1] a[j] a j a[j-1] a j-1 j 1 {
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                } bigger = a[j-1] bigger a[j-1] a j-1 j 1 a[j-1] = a[j] a[j-1] a j-1 j 1 a[j] a j a[j] = bigger a[j] a j bigger count++ count for(k=0; k<N-1;k++){
            System.out.print(a[k]+ " ");
        } k=0; k=0 k 0 k<N-1 k N-1 N 1 k++ k++ k {
            System.out.print(a[k]+ " ");
        } {
            System.out.print(a[k]+ " ");
        } System.out.print(a[k]+ " ") System.out.print System.out System System.out a[k]+ " " a[k] a k " " if(k == N-1){
            System.out.println(a[k]);
        } k == N-1 k N-1 N 1 {
            System.out.println(a[k]);
        } System.out.println(a[k]) System.out.println System.out System System.out a[k] a k 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 bigger ;
        int a[] = new int[N];
        int i,j,k,x ;
        int count =0;
        for (x =0 ; x < N ; x++){
            a[x] = sc.nextInt();
        }
        for (i = 0; a.length > i;i++ ){
            for(j=N-1;j>=i+1;j--){
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            }
        }
        for(k=0; k<N-1;k++){
            System.out.print(a[k]+ " ");
        }
        if(k == N-1){
            System.out.println(a[k]);
        }
        System.out.println(count);
    }

} public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int bigger ;
        int a[] = new int[N];
        int i,j,k,x ;
        int count =0;
        for (x =0 ; x < N ; x++){
            a[x] = sc.nextInt();
        }
        for (i = 0; a.length > i;i++ ){
            for(j=N-1;j>=i+1;j--){
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            }
        }
        for(k=0; k<N-1;k++){
            System.out.print(a[k]+ " ");
        }
        if(k == N-1){
            System.out.println(a[k]);
        }
        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 bigger ;
        int a[] = new int[N];
        int i,j,k,x ;
        int count =0;
        for (x =0 ; x < N ; x++){
            a[x] = sc.nextInt();
        }
        for (i = 0; a.length > i;i++ ){
            for(j=N-1;j>=i+1;j--){
                if(a[j] <a[j-1]){
                    bigger = a[j-1];
                    a[j-1] = a[j];
                    a[j] = bigger;
                    count++;
                }
            }
        }
        for(k=0; k<N-1;k++){
            System.out.print(a[k]+ " ");
        }
        if(k == N-1){
            System.out.println(a[k]);
        }
        System.out.println(count);
    }

}