title: Number Subsequences Ab String Repeated K Times
signature: pub fn number_subsequences_ab_string_repeated_k_times(s: String, k: i32) -> f32 {
test_code: use std::collections::HashMap;
  use std::collections::HashSet;
  use std::cmp::*;
  use std::collections::*;
  use std::fmt::*; 
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  pub fn validate_solution(actual: f32, expected: f32)->bool{
  return (actual - expected).abs() < 1e-06
  }
  pub fn driver(s: String, k: i32, expected: f32)->String{
      if validate_solution(PLACEHOLDER_FN_NAME(s, k), expected) {
        return "PASSED".to_string();
      };
      return "FAILED".to_string();
  
  }
  
  fn main() {
      println!("TEST-0...{}", driver(
        "abbc".to_string(), 96, 
        9312.0
      ));
      
      println!("TEST-1...{}", driver(
        "abahk".to_string(), 7, 
        49.0
      ));
      
      println!("TEST-2...{}", driver(
        "hugbabab".to_string(), 5, 
        75.0
      ));
      
      println!("TEST-3...{}", driver(
        "abadbc".to_string(), 60, 
        7260.0
      ));
      
      println!("TEST-4...{}", driver(
        "nkg9".to_string(), 8, 
        0.0
      ));
      
      println!("TEST-5...{}", driver(
        "jh7dab".to_string(), 41, 
        861.0
      ));
      
      println!("TEST-6...{}", driver(
        "abd".to_string(), 87, 
        3828.0
      ));
      
      println!("TEST-7...{}", driver(
        "aabb8yk".to_string(), 4, 
        40.0
      ));
      
      println!("TEST-8...{}", driver(
        "1111".to_string(), 18, 
        0.0
      ));
      
      println!("TEST-9...{}", driver(
        "PFXAhr".to_string(), 8, 
        0.0
      ));
      
  }
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;
  }