from libc.string cimport memset
from libc.stdio cimport scanf, printf

ctypedef long long LL
cdef:
    LL mod = 10**9+7
    LL inf = 10**18


cdef:
    LL N, Q, D, M, DM, k, i, q, res
    LL query[100]
    char S[1001001]
    
scanf("%I64d", &N)
scanf("%s", S)
scanf("%I64d", &Q)
for i in range(Q):
    scanf("%I64d", &query[i])

for q in range(Q):
    k = query[q]
    D = 0
    M = 0
    DM = 0
    res = 0
    for i in range(N):
        if i >= k:
            if S[i-k] == b"D":
                DM -= M
                D -= 1
            elif S[i-k] == b"M":
                M -= 1
        if S[i] == b"D":
            D += 1
        elif S[i] == b"M":
            DM += D
            M += 1
        elif S[i] == b"C":
            res += DM
    print(res)
