import java.util.Scanner;

class Main{
  static void trace(int[] a){
    int i;
    for(i = 0; i < a.length - 1; i++)
      System.out.print(a[i] + " ");
    System.out.println(a[i]);
  }

  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int a[] = new int[n];
    for(int i = 0; i < n; i++)
      a[i] = stdIn.nextInt();

    int count = 0;
    for(int i = 0; i < n; i++)
      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;
          count++;
        }
      }

    trace(a);
    System.out.println(count);

  }
} import java.util.Scanner; Scanner java.util class Main{
  static void trace(int[] a){
    int i;
    for(i = 0; i < a.length - 1; i++)
      System.out.print(a[i] + " ");
    System.out.println(a[i]);
  }

  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int a[] = new int[n];
    for(int i = 0; i < n; i++)
      a[i] = stdIn.nextInt();

    int count = 0;
    for(int i = 0; i < n; i++)
      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;
          count++;
        }
      }

    trace(a);
    System.out.println(count);

  }
} Main static void trace(int[] a){
    int i;
    for(i = 0; i < a.length - 1; i++)
      System.out.print(a[i] + " ");
    System.out.println(a[i]);
  } trace {
    int i;
    for(i = 0; i < a.length - 1; i++)
      System.out.print(a[i] + " ");
    System.out.println(a[i]);
  } int i; i for(i = 0; i < a.length - 1; i++)
      System.out.print(a[i] + " "); i = 0; i = 0 i 0 i < a.length - 1 i a.length - 1 a.length a a.length 1 i++ i++ i System.out.print(a[i] + " "); System.out.print(a[i] + " ") System.out.print System.out System System.out a[i] + " " a[i] a i " " System.out.println(a[i]) System.out.println System.out System System.out a[i] a i int[] a a public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int a[] = new int[n];
    for(int i = 0; i < n; i++)
      a[i] = stdIn.nextInt();

    int count = 0;
    for(int i = 0; i < n; i++)
      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;
          count++;
        }
      }

    trace(a);
    System.out.println(count);

  } main {
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int a[] = new int[n];
    for(int i = 0; i < n; i++)
      a[i] = stdIn.nextInt();

    int count = 0;
    for(int i = 0; i < n; i++)
      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;
          count++;
        }
      }

    trace(a);
    System.out.println(count);

  } Scanner stdIn = new Scanner(System.in); stdIn new Scanner(System.in) int n = stdIn.nextInt(); n stdIn.nextInt() stdIn.nextInt stdIn int a[] = new int[n]; a new int[n] n for(int i = 0; i < n; i++)
      a[i] = stdIn.nextInt(); int i = 0; int i = 0; i 0 i < n i n i++ i++ i a[i] = stdIn.nextInt(); a[i] = stdIn.nextInt() a[i] a i stdIn.nextInt() stdIn.nextInt stdIn int count = 0; count 0 for(int i = 0; i < n; i++)
      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;
          count++;
        }
      } int i = 0; int i = 0; i 0 i < n i n i++ i++ i 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;
          count++;
        }
      } 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;
          count++;
        }
      } 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;
          count++;
        }
      } {
        if(a[j] < a[j-1]){
          int tmp = a[j];
          a[j] = a[j-1];
          a[j-1] = tmp;
          count++;
        }
      } if(a[j] < a[j-1]){
          int tmp = a[j];
          a[j] = a[j-1];
          a[j-1] = tmp;
          count++;
        } 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;
          count++;
        } 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 count++ count trace(a) trace a System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.util.Scanner;

class Main{
  static void trace(int[] a){
    int i;
    for(i = 0; i < a.length - 1; i++)
      System.out.print(a[i] + " ");
    System.out.println(a[i]);
  }

  public static void main(String[] args){
    Scanner stdIn = new Scanner(System.in);
    int n = stdIn.nextInt();
    int a[] = new int[n];
    for(int i = 0; i < n; i++)
      a[i] = stdIn.nextInt();

    int count = 0;
    for(int i = 0; i < n; i++)
      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;
          count++;
        }
      }

    trace(a);
    System.out.println(count);

  }
}