import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] bubNum = new int[sc.nextInt()];
        
        for(int i = 0; i < bubNum.length; i++){
            bubNum[i] = sc.nextInt();
        }
        BubbleSort bs = new BubbleSort(bubNum);
        bs.changeOfBubNum();
        bs.outPutOfBubNum();
        bs.outPutOfBubCount();
    }
}

class BubbleSort{
    int[] bubNum;
    public BubbleSort(int[] bubNum){
        this.bubNum = bubNum;
    }
    
    int count = 0;
    public void changeOfBubNum(){
        int minNum = 0;
        for(int i = 0, j; i < bubNum.length; i++){
            if(i == 0){
                continue;
            }
            minNum = bubNum[i];
            j = i - 1;
            while(j >= 0 && bubNum[j] > minNum){
                bubNum[j + 1] = bubNum[j];
                count++;
                j--;
            }
            bubNum[j + 1] = minNum;
        }
    }
    
    public void outPutOfBubNum(){
        for(int i = 0; i < bubNum.length; i++){
            if(i == 0){
                System.out.print(bubNum[i]);
                continue;
            }
            System.out.print(" " + bubNum[i]);
        }
        System.out.print("\n");
    }
    
    public void outPutOfBubCount(){
         System.out.println(count);
    }
} import java.util.*; util.* java public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] bubNum = new int[sc.nextInt()];
        
        for(int i = 0; i < bubNum.length; i++){
            bubNum[i] = sc.nextInt();
        }
        BubbleSort bs = new BubbleSort(bubNum);
        bs.changeOfBubNum();
        bs.outPutOfBubNum();
        bs.outPutOfBubCount();
    }
} Main public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] bubNum = new int[sc.nextInt()];
        
        for(int i = 0; i < bubNum.length; i++){
            bubNum[i] = sc.nextInt();
        }
        BubbleSort bs = new BubbleSort(bubNum);
        bs.changeOfBubNum();
        bs.outPutOfBubNum();
        bs.outPutOfBubCount();
    } main {
        Scanner sc = new Scanner(System.in);
        int[] bubNum = new int[sc.nextInt()];
        
        for(int i = 0; i < bubNum.length; i++){
            bubNum[i] = sc.nextInt();
        }
        BubbleSort bs = new BubbleSort(bubNum);
        bs.changeOfBubNum();
        bs.outPutOfBubNum();
        bs.outPutOfBubCount();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int[] bubNum = new int[sc.nextInt()]; bubNum new int[sc.nextInt()] sc.nextInt() sc.nextInt sc for(int i = 0; i < bubNum.length; i++){
            bubNum[i] = sc.nextInt();
        } int i = 0; int i = 0; i 0 i < bubNum.length i bubNum.length bubNum bubNum.length i++ i++ i {
            bubNum[i] = sc.nextInt();
        } {
            bubNum[i] = sc.nextInt();
        } bubNum[i] = sc.nextInt() bubNum[i] bubNum i sc.nextInt() sc.nextInt sc BubbleSort bs = new BubbleSort(bubNum); bs new BubbleSort(bubNum) bs.changeOfBubNum() bs.changeOfBubNum bs bs.outPutOfBubNum() bs.outPutOfBubNum bs bs.outPutOfBubCount() bs.outPutOfBubCount bs String[] args args class BubbleSort{
    int[] bubNum;
    public BubbleSort(int[] bubNum){
        this.bubNum = bubNum;
    }
    
    int count = 0;
    public void changeOfBubNum(){
        int minNum = 0;
        for(int i = 0, j; i < bubNum.length; i++){
            if(i == 0){
                continue;
            }
            minNum = bubNum[i];
            j = i - 1;
            while(j >= 0 && bubNum[j] > minNum){
                bubNum[j + 1] = bubNum[j];
                count++;
                j--;
            }
            bubNum[j + 1] = minNum;
        }
    }
    
    public void outPutOfBubNum(){
        for(int i = 0; i < bubNum.length; i++){
            if(i == 0){
                System.out.print(bubNum[i]);
                continue;
            }
            System.out.print(" " + bubNum[i]);
        }
        System.out.print("\n");
    }
    
    public void outPutOfBubCount(){
         System.out.println(count);
    }
} BubbleSort int[] bubNum; bubNum int count = 0; count 0 public BubbleSort(int[] bubNum){
        this.bubNum = bubNum;
    } BubbleSort {
        this.bubNum = bubNum;
    } this.bubNum = bubNum this.bubNum this this.bubNum bubNum int[] bubNum bubNum public void changeOfBubNum(){
        int minNum = 0;
        for(int i = 0, j; i < bubNum.length; i++){
            if(i == 0){
                continue;
            }
            minNum = bubNum[i];
            j = i - 1;
            while(j >= 0 && bubNum[j] > minNum){
                bubNum[j + 1] = bubNum[j];
                count++;
                j--;
            }
            bubNum[j + 1] = minNum;
        }
    } changeOfBubNum {
        int minNum = 0;
        for(int i = 0, j; i < bubNum.length; i++){
            if(i == 0){
                continue;
            }
            minNum = bubNum[i];
            j = i - 1;
            while(j >= 0 && bubNum[j] > minNum){
                bubNum[j + 1] = bubNum[j];
                count++;
                j--;
            }
            bubNum[j + 1] = minNum;
        }
    } int minNum = 0; minNum 0 for(int i = 0, j; i < bubNum.length; i++){
            if(i == 0){
                continue;
            }
            minNum = bubNum[i];
            j = i - 1;
            while(j >= 0 && bubNum[j] > minNum){
                bubNum[j + 1] = bubNum[j];
                count++;
                j--;
            }
            bubNum[j + 1] = minNum;
        } int i = 0, j; int i = 0 i 0 j; j i < bubNum.length i bubNum.length bubNum bubNum.length i++ i++ i {
            if(i == 0){
                continue;
            }
            minNum = bubNum[i];
            j = i - 1;
            while(j >= 0 && bubNum[j] > minNum){
                bubNum[j + 1] = bubNum[j];
                count++;
                j--;
            }
            bubNum[j + 1] = minNum;
        } {
            if(i == 0){
                continue;
            }
            minNum = bubNum[i];
            j = i - 1;
            while(j >= 0 && bubNum[j] > minNum){
                bubNum[j + 1] = bubNum[j];
                count++;
                j--;
            }
            bubNum[j + 1] = minNum;
        } if(i == 0){
                continue;
            } i == 0 i 0 {
                continue;
            } continue; minNum = bubNum[i] minNum bubNum[i] bubNum i j = i - 1 j i - 1 i 1 while(j >= 0 && bubNum[j] > minNum){
                bubNum[j + 1] = bubNum[j];
                count++;
                j--;
            } j >= 0 && bubNum[j] > minNum j >= 0 j 0 bubNum[j] > minNum bubNum[j] bubNum j minNum {
                bubNum[j + 1] = bubNum[j];
                count++;
                j--;
            } bubNum[j + 1] = bubNum[j] bubNum[j + 1] bubNum j + 1 j 1 bubNum[j] bubNum j count++ count j-- j bubNum[j + 1] = minNum bubNum[j + 1] bubNum j + 1 j 1 minNum public void outPutOfBubNum(){
        for(int i = 0; i < bubNum.length; i++){
            if(i == 0){
                System.out.print(bubNum[i]);
                continue;
            }
            System.out.print(" " + bubNum[i]);
        }
        System.out.print("\n");
    } outPutOfBubNum {
        for(int i = 0; i < bubNum.length; i++){
            if(i == 0){
                System.out.print(bubNum[i]);
                continue;
            }
            System.out.print(" " + bubNum[i]);
        }
        System.out.print("\n");
    } for(int i = 0; i < bubNum.length; i++){
            if(i == 0){
                System.out.print(bubNum[i]);
                continue;
            }
            System.out.print(" " + bubNum[i]);
        } int i = 0; int i = 0; i 0 i < bubNum.length i bubNum.length bubNum bubNum.length i++ i++ i {
            if(i == 0){
                System.out.print(bubNum[i]);
                continue;
            }
            System.out.print(" " + bubNum[i]);
        } {
            if(i == 0){
                System.out.print(bubNum[i]);
                continue;
            }
            System.out.print(" " + bubNum[i]);
        } if(i == 0){
                System.out.print(bubNum[i]);
                continue;
            } i == 0 i 0 {
                System.out.print(bubNum[i]);
                continue;
            } System.out.print(bubNum[i]) System.out.print System.out System System.out bubNum[i] bubNum i continue; System.out.print(" " + bubNum[i]) System.out.print System.out System System.out " " + bubNum[i] " " bubNum[i] bubNum i System.out.print("\n") System.out.print System.out System System.out "\n" public void outPutOfBubCount(){
         System.out.println(count);
    } outPutOfBubCount {
         System.out.println(count);
    } System.out.println(count) System.out.println System.out System System.out count public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] bubNum = new int[sc.nextInt()];
        
        for(int i = 0; i < bubNum.length; i++){
            bubNum[i] = sc.nextInt();
        }
        BubbleSort bs = new BubbleSort(bubNum);
        bs.changeOfBubNum();
        bs.outPutOfBubNum();
        bs.outPutOfBubCount();
    }
} public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] bubNum = new int[sc.nextInt()];
        
        for(int i = 0; i < bubNum.length; i++){
            bubNum[i] = sc.nextInt();
        }
        BubbleSort bs = new BubbleSort(bubNum);
        bs.changeOfBubNum();
        bs.outPutOfBubNum();
        bs.outPutOfBubCount();
    }
} Main
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int[] bubNum = new int[sc.nextInt()];
        
        for(int i = 0; i < bubNum.length; i++){
            bubNum[i] = sc.nextInt();
        }
        BubbleSort bs = new BubbleSort(bubNum);
        bs.changeOfBubNum();
        bs.outPutOfBubNum();
        bs.outPutOfBubCount();
    }
}

class BubbleSort{
    int[] bubNum;
    public BubbleSort(int[] bubNum){
        this.bubNum = bubNum;
    }
    
    int count = 0;
    public void changeOfBubNum(){
        int minNum = 0;
        for(int i = 0, j; i < bubNum.length; i++){
            if(i == 0){
                continue;
            }
            minNum = bubNum[i];
            j = i - 1;
            while(j >= 0 && bubNum[j] > minNum){
                bubNum[j + 1] = bubNum[j];
                count++;
                j--;
            }
            bubNum[j + 1] = minNum;
        }
    }
    
    public void outPutOfBubNum(){
        for(int i = 0; i < bubNum.length; i++){
            if(i == 0){
                System.out.print(bubNum[i]);
                continue;
            }
            System.out.print(" " + bubNum[i]);
        }
        System.out.print("\n");
    }
    
    public void outPutOfBubCount(){
         System.out.println(count);
    }
}
