N = gets.to_i
S = gets.chomp.split('')
Q = gets.to_i
K = gets.split.map(&:to_i)

require 'pp'
def debug obj
  # PP.pp obj, STDERR
end

STRD = 'D'.freeze
STRM = 'M'.freeze
STRC = 'C'.freeze
d_list = []
c_list = []
m_sum = Array.new(N, 0)
c_sum = Array.new(N, 0)

S.each_with_index do |s, i|
  d_list.push(i) if s == STRD
  c_list.push(i) if s == STRC
  m_sum[i] = m_sum[i-1] + (s == STRM ? 1 : 0)
  c_sum[i] = c_sum[i-1] + (s == STRC ? 1 : 0)
end
# debug m_sum
# debug c_sum
Q.times do |q|
  k = K[q]
  result = 0
  d_list.each do |d|
    c_list.each do |c|
      next if c < d || c-d >= k
      result += m_sum[c] - m_sum[d]
    end
  end
  puts result
end
