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

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int[] array=new int[n];
    for(int i=0;i<array.length;i++){
      array[i]=Integer.parseInt(scan.next());
    }

    int count=0;
    for(int i=0;i<array.length-1;i++){
      for(int j=array.length-1;j>i;j--){
        if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        }
      }
    }

    for(int i=0;i<array.length;i++){
      if(i<array.length-1){
        System.out.print(array[i]);
        System.out.print(" ");
      }else{
        System.out.println(array[i]);
      }
    }
    System.out.println(count);
  }
} import java.io.*; io.* java import java.util.*; util.* java class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int[] array=new int[n];
    for(int i=0;i<array.length;i++){
      array[i]=Integer.parseInt(scan.next());
    }

    int count=0;
    for(int i=0;i<array.length-1;i++){
      for(int j=array.length-1;j>i;j--){
        if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        }
      }
    }

    for(int i=0;i<array.length;i++){
      if(i<array.length-1){
        System.out.print(array[i]);
        System.out.print(" ");
      }else{
        System.out.println(array[i]);
      }
    }
    System.out.println(count);
  }
} Main public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int[] array=new int[n];
    for(int i=0;i<array.length;i++){
      array[i]=Integer.parseInt(scan.next());
    }

    int count=0;
    for(int i=0;i<array.length-1;i++){
      for(int j=array.length-1;j>i;j--){
        if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        }
      }
    }

    for(int i=0;i<array.length;i++){
      if(i<array.length-1){
        System.out.print(array[i]);
        System.out.print(" ");
      }else{
        System.out.println(array[i]);
      }
    }
    System.out.println(count);
  } main {
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int[] array=new int[n];
    for(int i=0;i<array.length;i++){
      array[i]=Integer.parseInt(scan.next());
    }

    int count=0;
    for(int i=0;i<array.length-1;i++){
      for(int j=array.length-1;j>i;j--){
        if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        }
      }
    }

    for(int i=0;i<array.length;i++){
      if(i<array.length-1){
        System.out.print(array[i]);
        System.out.print(" ");
      }else{
        System.out.println(array[i]);
      }
    }
    System.out.println(count);
  } Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int n=Integer.parseInt(scan.next()); n Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan int[] array=new int[n]; array new int[n] n for(int i=0;i<array.length;i++){
      array[i]=Integer.parseInt(scan.next());
    } int i=0; int i=0; i 0 i<array.length i array.length array array.length i++ i++ i {
      array[i]=Integer.parseInt(scan.next());
    } {
      array[i]=Integer.parseInt(scan.next());
    } array[i]=Integer.parseInt(scan.next()) array[i] array i Integer.parseInt(scan.next()) Integer.parseInt Integer scan.next() scan.next scan int count=0; count 0 for(int i=0;i<array.length-1;i++){
      for(int j=array.length-1;j>i;j--){
        if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        }
      }
    } int i=0; int i=0; i 0 i<array.length-1 i array.length-1 array.length array array.length 1 i++ i++ i {
      for(int j=array.length-1;j>i;j--){
        if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        }
      }
    } {
      for(int j=array.length-1;j>i;j--){
        if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        }
      }
    } for(int j=array.length-1;j>i;j--){
        if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        }
      } int j=array.length-1; int j=array.length-1; j array.length-1 array.length array array.length 1 j>i j i j-- j-- j {
        if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        }
      } {
        if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        }
      } if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        } array[j]<array[j-1] array[j] array j array[j-1] array j-1 j 1 {
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        } int tmp=array[j-1]; tmp array[j-1] array j-1 j 1 array[j-1]=array[j] array[j-1] array j-1 j 1 array[j] array j array[j]=tmp array[j] array j tmp count++ count for(int i=0;i<array.length;i++){
      if(i<array.length-1){
        System.out.print(array[i]);
        System.out.print(" ");
      }else{
        System.out.println(array[i]);
      }
    } int i=0; int i=0; i 0 i<array.length i array.length array array.length i++ i++ i {
      if(i<array.length-1){
        System.out.print(array[i]);
        System.out.print(" ");
      }else{
        System.out.println(array[i]);
      }
    } {
      if(i<array.length-1){
        System.out.print(array[i]);
        System.out.print(" ");
      }else{
        System.out.println(array[i]);
      }
    } if(i<array.length-1){
        System.out.print(array[i]);
        System.out.print(" ");
      }else{
        System.out.println(array[i]);
      } i<array.length-1 i array.length-1 array.length array array.length 1 {
        System.out.print(array[i]);
        System.out.print(" ");
      } System.out.print(array[i]) System.out.print System.out System System.out array[i] array i System.out.print(" ") System.out.print System.out System System.out " " {
        System.out.println(array[i]);
      } System.out.println(array[i]) System.out.println System.out System System.out array[i] array i System.out.println(count) System.out.println System.out System System.out count String[] args args
import java.io.*;
import java.util.*;

class Main{
  public static void main(String[] args) throws IOException{
    Scanner scan=new Scanner(System.in);
    int n=Integer.parseInt(scan.next());
    int[] array=new int[n];
    for(int i=0;i<array.length;i++){
      array[i]=Integer.parseInt(scan.next());
    }

    int count=0;
    for(int i=0;i<array.length-1;i++){
      for(int j=array.length-1;j>i;j--){
        if(array[j]<array[j-1]){
          int tmp=array[j-1];
          array[j-1]=array[j];
          array[j]=tmp;
          count++;
        }
      }
    }

    for(int i=0;i<array.length;i++){
      if(i<array.length-1){
        System.out.print(array[i]);
        System.out.print(" ");
      }else{
        System.out.println(array[i]);
      }
    }
    System.out.println(count);
  }
}
