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: n = int(input()) + 1
  s = "?" + input()
  q = int(input())
  k = list(map(int, input().split()))
  
  p_d = []
  cnt_m = [0] * n
  cnt_c = [0] * n
  
  for i, si in enumerate(s[1:], 1):
      cnt_m[i] = cnt_m[i - 1]
      cnt_c[i] = cnt_c[i - 1]
      if si == "D":
          p_d.append(i)
      elif si == "M":
          cnt_m[i] += 1
      elif si == "C":
          cnt_c[i] += 1
  
  left_c = [0] * n
  for i in range(1, n):
      left_c[i] = left_c[i - 1]
      if s[i] == "M":
          left_c[i] += cnt_c[i]
  
  # print(cnt_m)
  # print(cnt_c)
  # print(left_c)
  
  ans = []
  for ki in k:
      tmp = 0
      for di in p_d:
          x = cnt_m[min(di + ki - 1, n - 1)] - cnt_m[di - 1]
          y = cnt_c[min(di + ki - 1, n - 1)]
          tmp += x * y - left_c[min(di + ki - 1, n - 1)] + left_c[di - 1]
      ans.append(tmp)
  
  print("\n".join(map(str, ans)))
  
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* * *"}]