import java.io.*;
import java.util.*;



class Main{
    //読み込みのテンプレ(stringオブジェクトまで)
    
    static int N;
    static int[] sequence;
    static int count;
    
    public static void main(String[] args) throws IOException{
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        
        int[] sequence = new int[N];
        
        for(int i=0;i<N;i++){
            sequence[i]=scanner.nextInt();
        }
        
        sequence =  doBubblesort(sequence);
        showResult(sequence);
        System.out.println(count);
    }
    
    
    public static int[] doBubblesort(int[] sequence){
        for(int i=0;i<sequence.length-1;i++){
            for(int j=sequence.length-1;j>i;j--){
                if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                }
            }
        }
        
        return sequence;
    }
    
    
    public static void showResult(int[] sequence){
        for(int i =0;i<sequence.length-1;i++){
            int number = sequence[i];
            System.out.print(number + " ");
        }
        
        System.out.println(sequence[sequence.length-1]);
    }
    
} import java.io.*; io.* java import java.util.*; util.* java class Main{
    //読み込みのテンプレ(stringオブジェクトまで)
    
    static int N;
    static int[] sequence;
    static int count;
    
    public static void main(String[] args) throws IOException{
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        
        int[] sequence = new int[N];
        
        for(int i=0;i<N;i++){
            sequence[i]=scanner.nextInt();
        }
        
        sequence =  doBubblesort(sequence);
        showResult(sequence);
        System.out.println(count);
    }
    
    
    public static int[] doBubblesort(int[] sequence){
        for(int i=0;i<sequence.length-1;i++){
            for(int j=sequence.length-1;j>i;j--){
                if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                }
            }
        }
        
        return sequence;
    }
    
    
    public static void showResult(int[] sequence){
        for(int i =0;i<sequence.length-1;i++){
            int number = sequence[i];
            System.out.print(number + " ");
        }
        
        System.out.println(sequence[sequence.length-1]);
    }
    
} Main static int N; N static int[] sequence; sequence static int count; count public static void main(String[] args) throws IOException{
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        
        int[] sequence = new int[N];
        
        for(int i=0;i<N;i++){
            sequence[i]=scanner.nextInt();
        }
        
        sequence =  doBubblesort(sequence);
        showResult(sequence);
        System.out.println(count);
    } main {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        
        int[] sequence = new int[N];
        
        for(int i=0;i<N;i++){
            sequence[i]=scanner.nextInt();
        }
        
        sequence =  doBubblesort(sequence);
        showResult(sequence);
        System.out.println(count);
    } Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int N = scanner.nextInt(); N scanner.nextInt() scanner.nextInt scanner int[] sequence = new int[N]; sequence new int[N] N for(int i=0;i<N;i++){
            sequence[i]=scanner.nextInt();
        } int i=0; int i=0; i 0 i<N i N i++ i++ i {
            sequence[i]=scanner.nextInt();
        } {
            sequence[i]=scanner.nextInt();
        } sequence[i]=scanner.nextInt() sequence[i] sequence i scanner.nextInt() scanner.nextInt scanner sequence =  doBubblesort(sequence) sequence doBubblesort(sequence) doBubblesort sequence showResult(sequence) showResult sequence System.out.println(count) System.out.println System.out System System.out count String[] args args public static int[] doBubblesort(int[] sequence){
        for(int i=0;i<sequence.length-1;i++){
            for(int j=sequence.length-1;j>i;j--){
                if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                }
            }
        }
        
        return sequence;
    } doBubblesort {
        for(int i=0;i<sequence.length-1;i++){
            for(int j=sequence.length-1;j>i;j--){
                if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                }
            }
        }
        
        return sequence;
    } for(int i=0;i<sequence.length-1;i++){
            for(int j=sequence.length-1;j>i;j--){
                if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                }
            }
        } int i=0; int i=0; i 0 i<sequence.length-1 i sequence.length-1 sequence.length sequence sequence.length 1 i++ i++ i {
            for(int j=sequence.length-1;j>i;j--){
                if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                }
            }
        } {
            for(int j=sequence.length-1;j>i;j--){
                if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                }
            }
        } for(int j=sequence.length-1;j>i;j--){
                if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                }
            } int j=sequence.length-1; int j=sequence.length-1; j sequence.length-1 sequence.length sequence sequence.length 1 j>i j i j-- j-- j {
                if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                }
            } {
                if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                }
            } if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                } sequence[j] < sequence[j-1] sequence[j] sequence j sequence[j-1] sequence j-1 j 1 {
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                } int x = sequence[j]; x sequence[j] sequence j int y = sequence[j-1]; y sequence[j-1] sequence j-1 j 1 sequence[j] = y sequence[j] sequence j y sequence[j-1]= x sequence[j-1] sequence j-1 j 1 x count++ count return sequence; sequence int[] sequence sequence public static void showResult(int[] sequence){
        for(int i =0;i<sequence.length-1;i++){
            int number = sequence[i];
            System.out.print(number + " ");
        }
        
        System.out.println(sequence[sequence.length-1]);
    } showResult {
        for(int i =0;i<sequence.length-1;i++){
            int number = sequence[i];
            System.out.print(number + " ");
        }
        
        System.out.println(sequence[sequence.length-1]);
    } for(int i =0;i<sequence.length-1;i++){
            int number = sequence[i];
            System.out.print(number + " ");
        } int i =0; int i =0; i 0 i<sequence.length-1 i sequence.length-1 sequence.length sequence sequence.length 1 i++ i++ i {
            int number = sequence[i];
            System.out.print(number + " ");
        } {
            int number = sequence[i];
            System.out.print(number + " ");
        } int number = sequence[i]; number sequence[i] sequence i System.out.print(number + " ") System.out.print System.out System System.out number + " " number " " System.out.println(sequence[sequence.length-1]) System.out.println System.out System System.out sequence[sequence.length-1] sequence sequence.length-1 sequence.length sequence sequence.length 1 int[] sequence sequence
import java.io.*;
import java.util.*;



class Main{
    //読み込みのテンプレ(stringオブジェクトまで)
    
    static int N;
    static int[] sequence;
    static int count;
    
    public static void main(String[] args) throws IOException{
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        
        int[] sequence = new int[N];
        
        for(int i=0;i<N;i++){
            sequence[i]=scanner.nextInt();
        }
        
        sequence =  doBubblesort(sequence);
        showResult(sequence);
        System.out.println(count);
    }
    
    
    public static int[] doBubblesort(int[] sequence){
        for(int i=0;i<sequence.length-1;i++){
            for(int j=sequence.length-1;j>i;j--){
                if(sequence[j] < sequence[j-1]){
                    int x = sequence[j];
                    int y = sequence[j-1];
                    sequence[j] = y;
                    sequence[j-1]= x;
                    count++;
                }
            }
        }
        
        return sequence;
    }
    
    
    public static void showResult(int[] sequence){
        for(int i =0;i<sequence.length-1;i++){
            int number = sequence[i];
            System.out.print(number + " ");
        }
        
        System.out.println(sequence[sequence.length-1]);
    }
    
}