import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        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();
        }
        sc.close();
        Sort s = new Sort( n, a );
        s.bubblesort();
        s.printA();
        System.out.println( s.count );
    }
}

class Sort {
    public int N;
    public int[] A;
    public int count;

    Sort( int N, int[] A ){
        this.N = N;
        this.A = A;
        this.count = 0;
    }

    public void bubblesort(){
        int tmp = 0;
        boolean flag = true;
        while( flag ){
            flag = false;
            for( int j = this.N-1; j > 0 ; j-- ){
                if( this.A[j] < this.A[j - 1] ){
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                }
            }
        }
    }

    public void printA(){
        for( int i = 0; i < this.N; i++ ){
            System.out.print( this.A[i] );
            if( i != this.N - 1 ){
                System.out.print(  " " );
            }
        }
        System.out.println("");
    }
} 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[] a = new int[n];
        for( int i = 0 ; i < n ; i++ ){
            a[i] = sc.nextInt();
        }
        sc.close();
        Sort s = new Sort( n, a );
        s.bubblesort();
        s.printA();
        System.out.println( s.count );
    }
} Main public static void main(String[] args) {
        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();
        }
        sc.close();
        Sort s = new Sort( n, a );
        s.bubblesort();
        s.printA();
        System.out.println( s.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();
        }
        sc.close();
        Sort s = new Sort( n, a );
        s.bubblesort();
        s.printA();
        System.out.println( s.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 sc.close() sc.close sc Sort s = new Sort( n, a ); s new Sort( n, a ) s.bubblesort() s.bubblesort s s.printA() s.printA s System.out.println( s.count ) System.out.println System.out System System.out s.count s s.count String[] args args class Sort {
    public int N;
    public int[] A;
    public int count;

    Sort( int N, int[] A ){
        this.N = N;
        this.A = A;
        this.count = 0;
    }

    public void bubblesort(){
        int tmp = 0;
        boolean flag = true;
        while( flag ){
            flag = false;
            for( int j = this.N-1; j > 0 ; j-- ){
                if( this.A[j] < this.A[j - 1] ){
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                }
            }
        }
    }

    public void printA(){
        for( int i = 0; i < this.N; i++ ){
            System.out.print( this.A[i] );
            if( i != this.N - 1 ){
                System.out.print(  " " );
            }
        }
        System.out.println("");
    }
} Sort public int N; N public int[] A; A public int count; count Sort( int N, int[] A ){
        this.N = N;
        this.A = A;
        this.count = 0;
    } Sort {
        this.N = N;
        this.A = A;
        this.count = 0;
    } this.N = N this.N this this.N N this.A = A this.A this this.A A this.count = 0 this.count this this.count 0 int N N int[] A A public void bubblesort(){
        int tmp = 0;
        boolean flag = true;
        while( flag ){
            flag = false;
            for( int j = this.N-1; j > 0 ; j-- ){
                if( this.A[j] < this.A[j - 1] ){
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                }
            }
        }
    } bubblesort {
        int tmp = 0;
        boolean flag = true;
        while( flag ){
            flag = false;
            for( int j = this.N-1; j > 0 ; j-- ){
                if( this.A[j] < this.A[j - 1] ){
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                }
            }
        }
    } int tmp = 0; tmp 0 boolean flag = true; flag true while( flag ){
            flag = false;
            for( int j = this.N-1; j > 0 ; j-- ){
                if( this.A[j] < this.A[j - 1] ){
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                }
            }
        } flag {
            flag = false;
            for( int j = this.N-1; j > 0 ; j-- ){
                if( this.A[j] < this.A[j - 1] ){
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                }
            }
        } flag = false flag false for( int j = this.N-1; j > 0 ; j-- ){
                if( this.A[j] < this.A[j - 1] ){
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                }
            } int j = this.N-1; int j = this.N-1; j this.N-1 this.N this this.N 1 j > 0 j 0 j-- j-- j {
                if( this.A[j] < this.A[j - 1] ){
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                }
            } {
                if( this.A[j] < this.A[j - 1] ){
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                }
            } if( this.A[j] < this.A[j - 1] ){
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                } this.A[j] < this.A[j - 1] this.A[j] this.A this this.A j this.A[j - 1] this.A this this.A j - 1 j 1 {
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                } tmp = this.A[j] tmp this.A[j] this.A this this.A j this.A[j] = this.A[j - 1] this.A[j] this.A this this.A j this.A[j - 1] this.A this this.A j - 1 j 1 this.A[j -1] = tmp this.A[j -1] this.A this this.A j -1 j 1 tmp flag = true flag true this.count++ this.count this this.count public void printA(){
        for( int i = 0; i < this.N; i++ ){
            System.out.print( this.A[i] );
            if( i != this.N - 1 ){
                System.out.print(  " " );
            }
        }
        System.out.println("");
    } printA {
        for( int i = 0; i < this.N; i++ ){
            System.out.print( this.A[i] );
            if( i != this.N - 1 ){
                System.out.print(  " " );
            }
        }
        System.out.println("");
    } for( int i = 0; i < this.N; i++ ){
            System.out.print( this.A[i] );
            if( i != this.N - 1 ){
                System.out.print(  " " );
            }
        } int i = 0; int i = 0; i 0 i < this.N i this.N this this.N i++ i++ i {
            System.out.print( this.A[i] );
            if( i != this.N - 1 ){
                System.out.print(  " " );
            }
        } {
            System.out.print( this.A[i] );
            if( i != this.N - 1 ){
                System.out.print(  " " );
            }
        } System.out.print( this.A[i] ) System.out.print System.out System System.out this.A[i] this.A this this.A i if( i != this.N - 1 ){
                System.out.print(  " " );
            } i != this.N - 1 i this.N - 1 this.N this this.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 "" public class Main {
    public static void main(String[] args) {
        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();
        }
        sc.close();
        Sort s = new Sort( n, a );
        s.bubblesort();
        s.printA();
        System.out.println( s.count );
    }
} public class Main {
    public static void main(String[] args) {
        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();
        }
        sc.close();
        Sort s = new Sort( n, a );
        s.bubblesort();
        s.printA();
        System.out.println( s.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[] a = new int[n];
        for( int i = 0 ; i < n ; i++ ){
            a[i] = sc.nextInt();
        }
        sc.close();
        Sort s = new Sort( n, a );
        s.bubblesort();
        s.printA();
        System.out.println( s.count );
    }
}

class Sort {
    public int N;
    public int[] A;
    public int count;

    Sort( int N, int[] A ){
        this.N = N;
        this.A = A;
        this.count = 0;
    }

    public void bubblesort(){
        int tmp = 0;
        boolean flag = true;
        while( flag ){
            flag = false;
            for( int j = this.N-1; j > 0 ; j-- ){
                if( this.A[j] < this.A[j - 1] ){
                    tmp = this.A[j];
                    this.A[j] = this.A[j - 1];
                    this.A[j -1] = tmp;
                    flag = true;
                    this.count++;
                }
            }
        }
    }

    public void printA(){
        for( int i = 0; i < this.N; i++ ){
            System.out.print( this.A[i] );
            if( i != this.N - 1 ){
                System.out.print(  " " );
            }
        }
        System.out.println("");
    }
}
