title: Number Subsequences Ab String Repeated K Times
signature: def number_subsequences_ab_string_repeated_k_times(s, k):
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;
  }
question_info.test_code: import array
  import bisect
  import collections
  import datetime
  import functools
  import heapq
  import itertools
  import math
  import queue
  import re
  import string
  import sys
  from typing import Any, Dict, List, Optional, Set
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  def validate_solution(actual, expected):
      return abs(actual - expected) < 1e-06
  
  def driver(s, k, expected):
      try:
          if validate_solution(PLACEHOLDER_FN_NAME(
              s, k),
              expected
          ):
              return "PASSED"
          return "FAILED"
      except Exception as exception_obj:
          return type(exception_obj).__name__
      
  if __name__ == "__main__":
      result = driver("abbc", 96, 9312.0)
      print(f"TEST-0...{result}")
  
      result = driver("abahk", 7, 49.0)
      print(f"TEST-1...{result}")
  
      result = driver("hugbabab", 5, 75.0)
      print(f"TEST-2...{result}")
  
      result = driver("abadbc", 60, 7260.0)
      print(f"TEST-3...{result}")
  
      result = driver("nkg9", 8, 0.0)
      print(f"TEST-4...{result}")
  
      result = driver("jh7dab", 41, 861.0)
      print(f"TEST-5...{result}")
  
      result = driver("abd", 87, 3828.0)
      print(f"TEST-6...{result}")
  
      result = driver("aabb8yk", 4, 40.0)
      print(f"TEST-7...{result}")
  
      result = driver("1111", 18, 0.0)
      print(f"TEST-8...{result}")
  
      result = driver("PFXAhr", 8, 0.0)
      print(f"TEST-9...{result}")
  
      sys.exit(0)
question_info.test_case_ids: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
question_info.entry_fn_name: number_subsequences_ab_string_repeated_k_times
question_info.test_list: [{"idx": 0, "outputs": 9312.0, "inputs": {"s": "abbc", "k": 96}}, {"idx": 1, "outputs": 49.0, "inputs": {"s": "abahk", "k": 7}}, {"idx": 2, "outputs": 75.0, "inputs": {"s": "hugbabab", "k": 5}}, {"idx": 3, "outputs": 7260.0, "inputs": {"s": "abadbc", "k": 60}}, {"idx": 4, "outputs": 0.0, "inputs": {"s": "nkg9", "k": 8}}, {"idx": 5, "outputs": 861.0, "inputs": {"s": "jh7dab", "k": 41}}, {"idx": 6, "outputs": 3828.0, "inputs": {"s": "abd", "k": 87}}, {"idx": 7, "outputs": 40.0, "inputs": {"s": "aabb8yk", "k": 4}}, {"idx": 8, "outputs": 0.0, "inputs": {"s": "1111", "k": 18}}, {"idx": 9, "outputs": 0.0, "inputs": {"s": "PFXAhr", "k": 8}}]
question_info.entry_cls_name: Solution