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())
  S=input()
  Q=int(input())
  K=[int(i) for i in input().split()
  def f(k):
      num=0
      L=[0,0,0]
      for i in range(N):
          if i-k>=0:
              if S[i-k]=='D':
                  L[0]-=1
                  L[2]-=L[1]
              elif S[i-k]=='M':
                  L[1]-=1
          if S[i]=='D':
              L[0]+=1
          elif S[i]=='M':
              L[1]+=1
              L[2]+=L[0]
          elif S[i]=='C':
              num+=L[2]
          #print(i,':',L,':',num)
      return num
  for k in K:
      print(f(k))
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* * *"}]