output_description: Print Q lines. The i-th line should contain the k_i-DMC number of the string
  S.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N
      S
      Q
      k_{0} k_{1} ... k_{Q-1}
attempt: # from collections import deque,defaultdict
  printn = lambda x: print(x, end="")
  inn = lambda: int(input())
  inl = lambda: list(map(int, input().split()))
  inm = lambda: map(int, input().split())
  ins = lambda: input().strip()
  DBG = True  # and False
  BIG = 10**18
  R = 10**9 + 7
  
  
  def ddprint(x):
      if DBG:
          print(x)
  
  
  n = inn()
  s = ins()
  q = inn()
  kl = inl()
  accd = [0] * (n + 1)
  accm = [0] * (n + 1)
  for i in range(n):
      accd[i] = accd[i - 1] + (1 if s[i] == "D" else 0)
      accm[i] = accm[i - 1] + (1 if s[i] == "M" else 0)
  # ddprint(accd)
  # ddprint(accm)
  for k in kl:
      # ddprint(k)
      dm = 0
      dmc = 0
      for i in range(1, n):
          if i >= k and s[i - k] == "D":
              dm -= accm[i - 1] - accm[i - k]
          if s[i] == "M":
              dm += accd[i - 1] - accd[max(-1, i - k)]
          if s[i] == "C":
              dmc += dm
          # ddprint(f"{i=} {dm=} {dmc=}")
      print(dmc)
  
problem_description: Statement
  
  In Dwango Co., Ltd., there is a content distribution system named 'Dwango
  Media Cluster', and it is called 'DMC' for short.  
  The name 'DMC' sounds cool for Niwango-kun, so he starts to define DMC-ness of
  a string.
  
  Given a string S of length N and an integer k (k \geq 3), he defines the _k
  -DMC number_ of S as the number of triples (a, b, c) of integers that satisfy
  the following conditions:
  
    * 0 \leq a < b < c \leq N - 1
    * S[a] = `D`
    * S[b] = `M`
    * S[c] = `C`
    * c-a < k
  
  Here S[a] is the a-th character of the string S. Indexing is zero-based, that
  is, 0 \leq a \leq N - 1 holds.
  
  For a string S and Q integers k_0, k_1, ..., k_{Q-1}, calculate the k_i-DMC
  number of S for each i (0 \leq i \leq Q-1).
samples: [{"input": "18\n    DWANGOMEDIACLUSTER\n    1\n    18", "output": "1\n    \n\n(a,b,c) = (0, 6, 11) satisfies the conditions.  \nStrangely, Dwango Media Cluster does not have so much DMC-ness by his\ndefinition.\n\n* * *"}, {"input": "18\n    DDDDDDMMMMMCCCCCCC\n    1\n    18", "output": "210\n    \n\nThe number of triples can be calculated as 6\\times 5\\times 7.\n\n* * *"}, {"input": "54\n    DIALUPWIDEAREANETWORKGAMINGOPERATIONCORPORATIONLIMITED\n    3\n    20 30 40", "output": "0\n    1\n    2\n    \n\n(a, b, c) = (0, 23, 36), (8, 23, 36) satisfy the conditions except the last\none, namely, c-a < k_i.  \nBy the way, DWANGO is an acronym for \"Dial-up Wide Area Network Gaming\nOperation\".\n\n* * *"}]