title: Count Possible Groups Size 2 3 Sum Multiple 3
signature: count_possible_groups_size_2_3_sum_multiple_3 <- function(arr, n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      abs(actual - expected) < 1e-06
  }
  
  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(1L, 3L, 6L, 12L, 18L, 31L, 36L, 43L, 47L, 59L, 64L, 64L, 69L, 69L, 94L, 98L, 98L), 12L, 
          90.0
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(94L, 46L, 64L, 18L, 70L, 22L, -98L, 52L, -26L, 34L, -22L, 22L, 40L, 66L, -72L, -66L, 86L, 84L, 12L, -38L, 28L, -60L, -10L, -30L, -78L, 76L, 62L, 74L, 24L, -64L, 0L, 92L, -20L, -66L, -52L), 23L, 
          655.0
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 29L, 
          3276.0
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(68L, 96L, 74L, 38L, 70L, 70L), 5L, 
          7.0
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-88L, -74L, -70L, -64L, -64L, -64L, -58L, -52L, -18L, -10L, -6L, 4L, 4L, 28L, 44L, 48L, 52L, 54L, 64L, 72L, 76L, 94L), 18L, 
          329.0
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 1L, 0L, 0L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 0L, 1L, 1L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 1L), 36L, 
          2310.0
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(9L, 12L, 14L, 21L, 27L, 28L, 45L, 50L, 54L, 57L, 58L, 62L, 78L, 82L, 91L, 92L, 95L), 9L, 
          49.0
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(16L, -46L, -32L, -36L, -84L, -14L, -18L, 16L, 54L, 90L, -4L), 8L, 
          24.0
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 1L, 1L), 3L, 
          1.0
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(53L, 32L, 54L, 84L, 79L, 37L, 44L, 30L, 92L, 53L, 89L, 95L), 8L, 
          29.0
      )))
  
  }
  
  main()
source_py: def count_possible_groups_size_2_3_sum_multiple_3(arr, n):
      c = [0, 0, 0]
      res = 0
      for i in range(0, n):
          c[(arr[i] % 3)] += 1
      res += ((c[0] * (c[0] - 1)) >> 1)
      res += (c[1] * c[2])
      res += (((c[0] * (c[0] - 1)) * (c[0] - 2)) / 6)
      res += (((c[1] * (c[1] - 1)) * (c[1] - 2)) / 6)
      res += (((c[2] * (c[2] - 1)) * (c[2] - 2)) / 6)
      res += ((c[0] * c[1]) * c[2])
      return res
source_cpp: int count_possible_groups_size_2_3_sum_multiple_3(vector<int> arr, int n) {
    int c [ 3 ] = {
      0 },
      i;
      int res = 0;
      for ( i = 0;
      i < n;
      i ++ ) c [ arr [ i ] % 3 ] ++;
      res += ( ( c [ 0 ] * ( c [ 0 ] - 1 ) ) >> 1 );
      res += c [ 1 ] * c [ 2 ];
      res += ( c [ 0 ] * ( c [ 0 ] - 1 ) * ( c [ 0 ] - 2 ) ) / 6;
      res += ( c [ 1 ] * ( c [ 1 ] - 1 ) * ( c [ 1 ] - 2 ) ) / 6;
      res += ( ( c [ 2 ] * ( c [ 2 ] - 1 ) * ( c [ 2 ] - 2 ) ) / 6 );
      res += c [ 0 ] * c [ 1 ] * c [ 2 ];
      return res;
    }