import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    int flag=1,i,j,N,cnt=0;
    
    //scanf N
    Scanner scan = new Scanner(System.in);
    N = scan.nextInt();
    
    //making array
    int[] A;
    A = new int[N];
    
    //complete array
    for(i=0;i<N;i++){
      A[i] = scan.nextInt();
    }
    
    //bubbling 
    while(flag==1){
      flag = 0;
      for(j=N-1;j>0;j--){
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      }
    }
    
    for(i=0;i<N-1;i++){
      System.out.print(A[i] + " ");
    }
    System.out.println(A[i]);
    System.out.println(cnt);

  }
} import java.util.Scanner; Scanner java.util public class Main{
  public static void main(String args[]){
    int flag=1,i,j,N,cnt=0;
    
    //scanf N
    Scanner scan = new Scanner(System.in);
    N = scan.nextInt();
    
    //making array
    int[] A;
    A = new int[N];
    
    //complete array
    for(i=0;i<N;i++){
      A[i] = scan.nextInt();
    }
    
    //bubbling 
    while(flag==1){
      flag = 0;
      for(j=N-1;j>0;j--){
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      }
    }
    
    for(i=0;i<N-1;i++){
      System.out.print(A[i] + " ");
    }
    System.out.println(A[i]);
    System.out.println(cnt);

  }
} Main public static void main(String args[]){
    int flag=1,i,j,N,cnt=0;
    
    //scanf N
    Scanner scan = new Scanner(System.in);
    N = scan.nextInt();
    
    //making array
    int[] A;
    A = new int[N];
    
    //complete array
    for(i=0;i<N;i++){
      A[i] = scan.nextInt();
    }
    
    //bubbling 
    while(flag==1){
      flag = 0;
      for(j=N-1;j>0;j--){
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      }
    }
    
    for(i=0;i<N-1;i++){
      System.out.print(A[i] + " ");
    }
    System.out.println(A[i]);
    System.out.println(cnt);

  } main {
    int flag=1,i,j,N,cnt=0;
    
    //scanf N
    Scanner scan = new Scanner(System.in);
    N = scan.nextInt();
    
    //making array
    int[] A;
    A = new int[N];
    
    //complete array
    for(i=0;i<N;i++){
      A[i] = scan.nextInt();
    }
    
    //bubbling 
    while(flag==1){
      flag = 0;
      for(j=N-1;j>0;j--){
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      }
    }
    
    for(i=0;i<N-1;i++){
      System.out.print(A[i] + " ");
    }
    System.out.println(A[i]);
    System.out.println(cnt);

  } int flag=1 flag 1 i i j j N N cnt=0; cnt 0 Scanner scan = new Scanner(System.in); scan new Scanner(System.in) N = scan.nextInt() N scan.nextInt() scan.nextInt scan int[] A; A A = new int[N] A new int[N] N for(i=0;i<N;i++){
      A[i] = scan.nextInt();
    } i=0; i=0 i 0 i<N i N i++ i++ i {
      A[i] = scan.nextInt();
    } {
      A[i] = scan.nextInt();
    } A[i] = scan.nextInt() A[i] A i scan.nextInt() scan.nextInt scan while(flag==1){
      flag = 0;
      for(j=N-1;j>0;j--){
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      }
    } flag==1 flag 1 {
      flag = 0;
      for(j=N-1;j>0;j--){
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      }
    } flag = 0 flag 0 for(j=N-1;j>0;j--){
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      } j=N-1; j=N-1 j N-1 N 1 j>0 j 0 j-- j-- j {
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      } {
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      } if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        } A[j]<A[j-1] A[j] A j A[j-1] A j-1 j 1 {
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        } int swap = A[j]; swap A[j] A j A[j] = A[j-1] A[j] A j A[j-1] A j-1 j 1 A[j-1] = swap A[j-1] A j-1 j 1 swap cnt++ cnt flag = 1 flag 1 for(i=0;i<N-1;i++){
      System.out.print(A[i] + " ");
    } i=0; i=0 i 0 i<N-1 i N-1 N 1 i++ i++ i {
      System.out.print(A[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 System.out.println(cnt) System.out.println System.out System System.out cnt String args[] args public class Main{
  public static void main(String args[]){
    int flag=1,i,j,N,cnt=0;
    
    //scanf N
    Scanner scan = new Scanner(System.in);
    N = scan.nextInt();
    
    //making array
    int[] A;
    A = new int[N];
    
    //complete array
    for(i=0;i<N;i++){
      A[i] = scan.nextInt();
    }
    
    //bubbling 
    while(flag==1){
      flag = 0;
      for(j=N-1;j>0;j--){
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      }
    }
    
    for(i=0;i<N-1;i++){
      System.out.print(A[i] + " ");
    }
    System.out.println(A[i]);
    System.out.println(cnt);

  }
} public class Main{
  public static void main(String args[]){
    int flag=1,i,j,N,cnt=0;
    
    //scanf N
    Scanner scan = new Scanner(System.in);
    N = scan.nextInt();
    
    //making array
    int[] A;
    A = new int[N];
    
    //complete array
    for(i=0;i<N;i++){
      A[i] = scan.nextInt();
    }
    
    //bubbling 
    while(flag==1){
      flag = 0;
      for(j=N-1;j>0;j--){
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      }
    }
    
    for(i=0;i<N-1;i++){
      System.out.print(A[i] + " ");
    }
    System.out.println(A[i]);
    System.out.println(cnt);

  }
} Main
import java.util.Scanner;

public class Main{
  public static void main(String args[]){
    int flag=1,i,j,N,cnt=0;
    
    //scanf N
    Scanner scan = new Scanner(System.in);
    N = scan.nextInt();
    
    //making array
    int[] A;
    A = new int[N];
    
    //complete array
    for(i=0;i<N;i++){
      A[i] = scan.nextInt();
    }
    
    //bubbling 
    while(flag==1){
      flag = 0;
      for(j=N-1;j>0;j--){
        if(A[j]<A[j-1]){
          int swap = A[j];
          A[j] = A[j-1];
          A[j-1] = swap;
          cnt++; //count
          flag = 1; //to be continue
        }
      }
    }
    
    for(i=0;i<N-1;i++){
      System.out.print(A[i] + " ");
    }
    System.out.println(A[i]);
    System.out.println(cnt);

  }
}