n1 = gets.to_i
wo = gets.chomp.split("")
n2 = gets.to_i
n3 = gets.chomp.split(" ").map(&:to_i)

for i in 0..n2 - 1
  ans = 0
  d = 0
  m = 0
  dm= 0
  for j in 0..n1 - 1
    if j >= n3[i]
      if wo[j - n3[i]] == "D"
        d -= 1
        dm -= m
      elsif wo[j - n3[i]] == "M"
        m -= 1
      end
    end
    if wo[j] == "D"
      d += 1
    elsif wo[j] == "M"
      m += 1
      dm += d
    elsif wo[j] == "C"
      ans += dm
    end
  end
  puts ans
end
