import java.util.*;
class Main{
  public static void main(String args[]){
    boolean flag = true;
    int tmp;
    int count = 0;
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int Array [] = new int[n];
    //input
    for(int i = 0; i<n; i++){
      Array[i] = sc.nextInt();
    }
    //bubblesort
    while(flag){
      flag = false;
      for(int j = n-1; j>0; j--){
        if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        }
      }
    }
    for(int i = 0; i<n-1; i++)System.out.printf("%d ",Array[i]);
    System.out.println(Array[n-1]);
    System.out.println(count);
  }
} import java.util.*; util.* java class Main{
  public static void main(String args[]){
    boolean flag = true;
    int tmp;
    int count = 0;
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int Array [] = new int[n];
    //input
    for(int i = 0; i<n; i++){
      Array[i] = sc.nextInt();
    }
    //bubblesort
    while(flag){
      flag = false;
      for(int j = n-1; j>0; j--){
        if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        }
      }
    }
    for(int i = 0; i<n-1; i++)System.out.printf("%d ",Array[i]);
    System.out.println(Array[n-1]);
    System.out.println(count);
  }
} Main public static void main(String args[]){
    boolean flag = true;
    int tmp;
    int count = 0;
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int Array [] = new int[n];
    //input
    for(int i = 0; i<n; i++){
      Array[i] = sc.nextInt();
    }
    //bubblesort
    while(flag){
      flag = false;
      for(int j = n-1; j>0; j--){
        if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        }
      }
    }
    for(int i = 0; i<n-1; i++)System.out.printf("%d ",Array[i]);
    System.out.println(Array[n-1]);
    System.out.println(count);
  } main {
    boolean flag = true;
    int tmp;
    int count = 0;
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int Array [] = new int[n];
    //input
    for(int i = 0; i<n; i++){
      Array[i] = sc.nextInt();
    }
    //bubblesort
    while(flag){
      flag = false;
      for(int j = n-1; j>0; j--){
        if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        }
      }
    }
    for(int i = 0; i<n-1; i++)System.out.printf("%d ",Array[i]);
    System.out.println(Array[n-1]);
    System.out.println(count);
  } boolean flag = true; flag true int tmp; tmp int count = 0; count 0 Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc int Array [] = new int[n]; Array new int[n] n for(int i = 0; i<n; i++){
      Array[i] = sc.nextInt();
    } int i = 0; int i = 0; i 0 i<n i n i++ i++ i {
      Array[i] = sc.nextInt();
    } {
      Array[i] = sc.nextInt();
    } Array[i] = sc.nextInt() Array[i] Array i sc.nextInt() sc.nextInt sc while(flag){
      flag = false;
      for(int j = n-1; j>0; j--){
        if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        }
      }
    } flag {
      flag = false;
      for(int j = n-1; j>0; j--){
        if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        }
      }
    } flag = false flag false for(int j = n-1; j>0; j--){
        if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        }
      } int j = n-1; int j = n-1; j n-1 n 1 j>0 j 0 j-- j-- j {
        if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        }
      } {
        if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        }
      } if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        } Array[j]<Array[j-1] Array[j] Array j Array[j-1] Array j-1 j 1 {
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        } tmp = Array[j] tmp Array[j] Array j Array[j] = Array[j-1] Array[j] Array j Array[j-1] Array j-1 j 1 Array[j-1] = tmp Array[j-1] Array j-1 j 1 tmp count++ count flag = true flag true for(int i = 0; i<n-1; i++)System.out.printf("%d ",Array[i]); int i = 0; int i = 0; i 0 i<n-1 i n-1 n 1 i++ i++ i System.out.printf("%d ",Array[i]); System.out.printf("%d ",Array[i]) System.out.printf System.out System System.out "%d " Array[i] Array i System.out.println(Array[n-1]) System.out.println System.out System System.out Array[n-1] Array n-1 n 1 System.out.println(count) System.out.println System.out System System.out count String args[] args
import java.util.*;
class Main{
  public static void main(String args[]){
    boolean flag = true;
    int tmp;
    int count = 0;
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int Array [] = new int[n];
    //input
    for(int i = 0; i<n; i++){
      Array[i] = sc.nextInt();
    }
    //bubblesort
    while(flag){
      flag = false;
      for(int j = n-1; j>0; j--){
        if(Array[j]<Array[j-1]){
          tmp = Array[j];
          Array[j] = Array[j-1];
          Array[j-1] = tmp;
          count++;
          flag = true;
        }
      }
    }
    for(int i = 0; i<n-1; i++)System.out.printf("%d ",Array[i]);
    System.out.println(Array[n-1]);
    System.out.println(count);
  }
}
