/* ALDS1_2_A */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();
      int n = Integer.parseInt(br.readLine());
      int[] array = new int[n];
      String[] str = br.readLine().split(" ");

      for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      }

      BubbleSort bs = new BubbleSort();
      bs.bubbleSort(array, n);

      for(int i = 0; i < n ; i++){
        sb.append(array[i]).append(" ");
      }
      sb.deleteCharAt(sb.length() - 1);
      sb.append("\n");
      sb.append(bs.getCount());

      System.out.println(sb);
    }catch(Exception e){
      System.out.println(e);
    }
  }
}

class BubbleSort
{
  private static int changeCount;

  public void bubbleSort(int[] A, int N)
  {
    changeCount = 0;
    boolean flag = true;
    int i = 0;

    while(flag){
      flag = false;
      for(int j = N-1; j > i; j--){
        if(A[j] < A[j-1]){
          int tmp = A[j];
          A[j] = A[j-1];
          A[j-1] = tmp;
          flag = true;
          changeCount++;
        }
      }
      i++;
    }
  }

  public int getCount()
  {
    return changeCount;
  }
}
/tmp/hf-datasets-cache/medium/datasets/42704881117311-config-parquet-and-info-qiankunmu-Project_CodeNet-896c9d36/hub/datasets--qiankunmu--Project_CodeNet_Python800_and_Java250/snapshots/c899fde44a77ba1cc14973ed3de064e4ff3aadc7/Project_CodeNet_Java250.tar.gz