title: Number Subsequences Ab String Repeated K Times
signature: function number_subsequences_ab_string_repeated_k_times(s, k)
test_code: using Printf
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  function validate_solution(actual, expected)
      return abs(actual - expected) < 1e-06
  end
  
  function driver(s, k, expected)
      try
  
          if validate_solution(PLACEHOLDER_FN_NAME(s, k), expected)
              return "PASSED";
          end
          return "FAILED";
      catch exception_obj
          return string(Base.typename(typeof(exception_obj)).wrapper);
      end
  end
  
  function main()
      
      result = driver("abbc", 96, 9312.0);
      @printf("TEST-0...%s\n",result);
      
      result = driver("abahk", 7, 49.0);
      @printf("TEST-1...%s\n",result);
      
      result = driver("hugbabab", 5, 75.0);
      @printf("TEST-2...%s\n",result);
      
      result = driver("abadbc", 60, 7260.0);
      @printf("TEST-3...%s\n",result);
      
      result = driver("nkg9", 8, 0.0);
      @printf("TEST-4...%s\n",result);
      
      result = driver("jh7dab", 41, 861.0);
      @printf("TEST-5...%s\n",result);
      
      result = driver("abd", 87, 3828.0);
      @printf("TEST-6...%s\n",result);
      
      result = driver("aabb8yk", 4, 40.0);
      @printf("TEST-7...%s\n",result);
      
      result = driver("1111", 18, 0.0);
      @printf("TEST-8...%s\n",result);
      
      result = driver("PFXAhr", 8, 0.0);
      @printf("TEST-9...%s\n",result);
      
  end
  
  main()
source_py: def number_subsequences_ab_string_repeated_k_times(s, K):
      n = len(s)
      c1 = 0
      c2 = 0
      C = 0
      for i in range(n):
          if (s[i] == 'a'):
              c1 += 1
          if (s[i] == 'b'):
              c2 += 1
              C += c1
      return ((C * K) + ((((K * (K - 1)) / 2) * c1) * c2))
source_cpp: int number_subsequences_ab_string_repeated_k_times(string s, int K) {
    int n = s . length ( );
    int C, c1 = 0, c2 = 0;
    for ( int i = 0;
    i < n;
    i ++ ) {
      if ( s [ i ] == 'a' ) c1 ++;
      if ( s [ i ] == 'b' ) {
        c2 ++;
        C += c1;
      }
    }
    return C * K + ( K * ( K - 1 ) / 2 ) * c1 * c2;
  }