title: Count Inversions Of Size Three In A Give Array 1
signature: count_inversions_of_size_three_in_a_give_array_1 <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(4L, 75L, 89L), 1L, 
          0L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(84L, -66L, -52L, 34L, -28L, -6L, 20L, 22L, -78L, -26L, 14L, 24L, -92L, -18L, 32L, -94L, -64L, -38L, 56L, 4L, -10L, 58L, -66L, -58L, -10L, -8L, -62L, -60L, -26L), 26L, 
          404L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L), 7L, 
          0L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(18L, 7L, 43L, 57L, 94L, 37L, 38L, 41L, 59L, 64L, 97L, 29L, 51L, 37L, 64L, 91L, 42L, 83L, 13L, 22L, 68L), 17L, 
          37L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-94L, -86L, -84L, -84L, -82L, -66L, -62L, -58L, -52L, -48L, -44L, -40L, -38L, -32L, -22L, -22L, -22L, -14L, -8L, -6L, -6L, 0L, 2L, 20L, 20L, 26L, 32L, 32L, 52L, 56L, 66L, 74L, 76L, 80L, 80L, 86L, 88L, 94L), 34L, 
          0L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L), 9L, 
          0L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(4L, 8L, 15L, 19L, 24L, 31L, 33L, 36L, 38L, 45L, 45L, 52L, 54L, 65L, 73L, 75L, 83L, 84L, 90L, 92L, 93L), 19L, 
          0L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(80L, -30L, -44L, 76L, -96L, 2L, 22L, -30L, 36L, -6L, 88L, -60L, -90L, -52L, 78L, 90L, -52L), 10L, 
          20L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 7L, 
          0L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(74L, 71L, 28L, 45L, 14L, 31L, 17L, 10L, 82L, 27L, 45L, 73L, 93L, 87L, 57L, 58L), 10L, 
          43L
      )))
  
  }
  
  main()
source_py: def count_inversions_of_size_three_in_a_give_array_1(arr, n):
      invcount = 0
      for i in range(1, (n - 1)):
          small = 0
          for j in range((i + 1), n):
              if (arr[i] > arr[j]):
                  small += 1
          great = 0
          for j in range((i - 1), (- 1), (- 1)):
              if (arr[i] < arr[j]):
                  great += 1
          invcount += (great * small)
      return invcount
source_cpp: int count_inversions_of_size_three_in_a_give_array_1(vector<int> arr, int n) {
    int invcount = 0;
    for ( int i = 1;
    i < n - 1;
    i ++ ) {
      int small = 0;
      for ( int j = i + 1;
      j < n;
      j ++ ) if ( arr [ i ] > arr [ j ] ) small ++;
      int great = 0;
      for ( int j = i - 1;
      j >= 0;
      j -- ) if ( arr [ i ] < arr [ j ] ) great ++;
      invcount += great * small;
    }
    return invcount;
  }