title: Number Subsequences Ab String Repeated K Times
signature: fun numberSubsequencesAbStringRepeatedKTimes(s: String, k: Int): Float {
test_code: package main
  
  import kotlin.text.*
  import kotlin.math.*
  
  
  // SOLUTION CODE
  // ===================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE
  // ===================================
  fun validateSolution(actual:Float, expected:Float):Boolean{
    return abs(actual - expected) < 1e-06f
  }
  fun driver(s: String, k: Int, expected:Float):String {
      try{
        if (validateSolution(PLACEHOLDER_FN_NAME(s, k), expected)) {
                return "PASSED"
        }
        return "FAILED"
      } catch (e: Exception){
        return e::class.simpleName as String
      }
  
  }
  
  fun main() {
      var result: String = ""
      result = driver("abbc", 96, 9312.0f)
      println("TEST-0...${result}")
      
      result = driver("abahk", 7, 49.0f)
      println("TEST-1...${result}")
      
      result = driver("hugbabab", 5, 75.0f)
      println("TEST-2...${result}")
      
      result = driver("abadbc", 60, 7260.0f)
      println("TEST-3...${result}")
      
      result = driver("nkg9", 8, 0.0f)
      println("TEST-4...${result}")
      
      result = driver("jh7dab", 41, 861.0f)
      println("TEST-5...${result}")
      
      result = driver("abd", 87, 3828.0f)
      println("TEST-6...${result}")
      
      result = driver("aabb8yk", 4, 40.0f)
      println("TEST-7...${result}")
      
      result = driver("1111", 18, 0.0f)
      println("TEST-8...${result}")
      
      result = driver("PFXAhr", 8, 0.0f)
      println("TEST-9...${result}")
      
          
  }
  
  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;
  }