/* 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;
  }
} import java.io.*; io.* java 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);
    }
  }
} 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);
    }
  } main {
    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);
    }
  } 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);
    } catch(Exception e){
      System.out.println(e);
    } Exception e {
      System.out.println(e);
    } System.out.println(e) System.out.println System.out System System.out e {
      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);
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) StringBuilder sb = new StringBuilder(); sb new StringBuilder() int n = Integer.parseInt(br.readLine()); n Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int[] array = new int[n]; array new int[n] n String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int i = 0; i < n; i++){
        array[i] = Integer.parseInt(str[i]);
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        array[i] = Integer.parseInt(str[i]);
      } {
        array[i] = Integer.parseInt(str[i]);
      } array[i] = Integer.parseInt(str[i]) array[i] array i Integer.parseInt(str[i]) Integer.parseInt Integer str[i] str i BubbleSort bs = new BubbleSort(); bs new BubbleSort() bs.bubbleSort(array, n) bs.bubbleSort bs array n for(int i = 0; i < n ; i++){
        sb.append(array[i]).append(" ");
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
        sb.append(array[i]).append(" ");
      } {
        sb.append(array[i]).append(" ");
      } sb.append(array[i]).append(" ") sb.append(array[i]).append sb.append(array[i]) sb.append sb array[i] array i " " sb.deleteCharAt(sb.length() - 1) sb.deleteCharAt sb sb.length() - 1 sb.length() sb.length sb 1 sb.append("\n") sb.append sb "\n" sb.append(bs.getCount()) sb.append sb bs.getCount() bs.getCount bs System.out.println(sb) System.out.println System.out System System.out sb String[] args args 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;
  }
} BubbleSort private static int changeCount; 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++;
    }
  } bubbleSort {
    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++;
    }
  } changeCount = 0 changeCount 0 boolean flag = true; flag true int i = 0; 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++;
    } 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++;
    } flag = false 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++;
        }
      } int j = N-1; int j = N-1; j N-1 N 1 j > i j i j-- j-- j {
        if(A[j] < A[j-1]){
          int tmp = A[j];
          A[j] = A[j-1];
          A[j-1] = tmp;
          flag = true;
          changeCount++;
        }
      } {
        if(A[j] < A[j-1]){
          int tmp = A[j];
          A[j] = A[j-1];
          A[j-1] = tmp;
          flag = true;
          changeCount++;
        }
      } if(A[j] < A[j-1]){
          int tmp = A[j];
          A[j] = A[j-1];
          A[j-1] = tmp;
          flag = true;
          changeCount++;
        } A[j] < A[j-1] A[j] A j A[j-1] A j-1 j 1 {
          int tmp = A[j];
          A[j] = A[j-1];
          A[j-1] = tmp;
          flag = true;
          changeCount++;
        } int tmp = A[j]; tmp A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = tmp A[j-1] A j-1 j 1 tmp flag = true flag true changeCount++ changeCount i++ i int[] A A int N N public int getCount()
  {
    return changeCount;
  } getCount {
    return changeCount;
  } return changeCount; changeCount
/* 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;
  }
}