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 ≥ 3), he defines the k-DMC number of S as the number of triples (a, b, c) of integers that satisfy certain conditions.

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 ≤ i ≤ Q-1).

Constraints:
- 3 ≤ N ≤ 10^6
- S consists of uppercase English letters
- 1 ≤ Q ≤ 75
- 3 ≤ k_i ≤ N
- All numbers given in input are integers

Input:
N
S
Q
k_{0} k_{1} ... k_{Q-1}

Output:
Print Q lines. The i-th line should contain the k_i-DMC number of the string S.

Sample Input/Output examples are provided.

# Buggy version:
N = int(input())
S = input()
Q = int(input())
K = [int(i) for i in input().split()]

for k in K:
    ans = 0

    d = m = dm = 0
    for i, si in enumerate(S):
        if 0 <= i - K:
            if S[i - K] == "D":
                d -= 1
                dm -= m
            elif S[i - K] == "M":
                m -= 1

        if si == "D":
            d += 1
        elif si == "M":
            m += 1
            dm += d
        elif si == "C":
            ans += dm

    print(ans)

# Fixed version:
N = int(input())
S = input()
Q = int(input())
K = [int(i) for i in input().split()]

for k in K:
    ans = 0

    d = m = dm = 0
    for i, si in enumerate(S):
        if 0 <= i - k:
            if S[i - k] == "D":
                d -= 1
                dm -= m
            elif S[i - k] == "M":
                m -= 1

        if si == "D":
            d += 1
        elif si == "M":
            m += 1
            dm += d
        elif si == "C":
            ans += dm

    print(ans)

# Buggy version:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
S = LS2()
Q = I()
K = LI()


def query(k):
    res = 0
    a = 0  # (i-k,i] にあるDの個数
    b = 0  # (i-k,i] にあるMの個数
    c = 0  # (i-k,i] にある(D,M)の個数
    for i in range(N):
        if i >= k:
            if S[i-k] == 'D':
                a -= 1
                c -= b
            elif S[i-k] == 'M':
                b -= 1
        if S[i] == 'D':
            a += 1
        elif S[i] == 'M':
            b += 1
            c += a
        elif S[i] == 'C':
            res += c


print(*[query(k) for k in K],sep='\n')

# Fixed version:
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N = I()
S = LS2()
Q = I()
K = LI()


def query(k):
    res = 0
    a = 0  # (i-k,i] にあるDの個数
    b = 0  # (i-k,i] にあるMの個数
    c = 0  # (i-k,i] にある(D,M)の個数
    for i in range(N):
        if i >= k:
            if S[i-k] == 'D':
                a -= 1
                c -= b
            elif S[i-k] == 'M':
                b -= 1
        if S[i] == 'D':
            a += 1
        elif S[i] == 'M':
            b += 1
            c += a
        elif S[i] == 'C':
            res += c
    return res


print(*[query(k) for k in K],sep='\n')

# Buggy version:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    q = int(input())
    K = list(map(int,input().split()))
    d = 0
    m = 0
    dm = 0

    # print(s)

    for i in range(q):
        ans = 0
        k = K[i]
        for j in range(n):

            if j-k >= 0:
                if s[j-k] == "D":
                    d -= 1
                    dm -= m
                elif s[j-k] == "M":
                    m -= 1

            if s[j] == "D":
                d += 1
            elif s[j] == "M":
                m += 1
                dm += d
            elif s[j] == "C":
                ans += dm
        print(ans)

if __name__ == "__main__":
    main()

# Fixed version:
import sys
input = sys.stdin.readline

def main():
    n = int(input())
    s = input()
    q = int(input())
    K = list(map(int,input().split()))
    # print(s)

    for i in range(q):
        ans = 0
        d = 0
        m = 0
        dm = 0
        k = K[i]
        for j in range(n):

            if j-k >= 0:
                if s[j-k] == "D":
                    d -= 1
                    dm -= m
                elif s[j-k] == "M":
                    m -= 1

            if s[j] == "D":
                d += 1
            elif s[j] == "M":
                m += 1
                dm += d
            elif s[j] == "C":
                ans += dm
        print(ans)

if __name__ == "__main__":
    main()

# Buggy version:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = [input().rstrip()]
    Q = int(input())
    k = list(map(int, input().split()))

    for l in k:
        D = 0
        M = 0
        tmp = 0
        ans = 0
        for i in range(N):
            if i >= l:
                if S[i-l] == 'D':
                    tmp -= M
                    D -= 1
                if S[i-l] == 'M':
                    M -= 1
            if S[i] == 'D':
                D += 1
            if S[i] == 'M':
                M += 1
                tmp += D
            if S[i] == 'C':
                ans += tmp
        print(ans)

main()

# Fixed version:
import sys
input = sys.stdin.readline

def main():
    N = int(input())
    S = input().rstrip()
    Q = int(input())
    k = list(map(int, input().split()))

    for l in k:
        D = 0
        M = 0
        tmp = 0
        ans = 0
        for i in range(N):
            if i >= l:
                if S[i-l] == 'D':
                    tmp -= M
                    D -= 1
                if S[i-l] == 'M':
                    M -= 1
            if S[i] == 'D':
                D += 1
            if S[i] == 'M':
                M += 1
                tmp += D
            if S[i] == 'C':
                ans += tmp
        print(ans)

main()

# Buggy version:
import sys
input=sys.stdin.readline
n=int(input())
l=tuple(input())
q=int(input())
kl=tuple(map(int,input().split()))
for i in range(q):
    k=kl[i]
    d=0
    m=0
    dm=0
    ans=0
    for j in range(n):
        if l[j]=='D':
            d+=1
        if l[j]=='M':
            m+=1
            dm+=d
        if l[j]=='C':
            ans+=dm
        if j>=k:
            if l[j-k]=='D':
                dm-=m
                d-=1
            if l[j-k]=='M':
                m-=1
    print(ans)


# Fixed version:
import sys
input=sys.stdin.readline
n=int(input())
l=input()
q=int(input())
kl=tuple(map(int,input().split()))
for k in kl:
    d=0
    m=0
    dm=0
    ans=0
    for j in range(n):
        if l[j]=='D':
            d+=1
        elif l[j]=='M':
            m+=1
            dm+=d
        elif l[j]=='C':
            ans+=dm
        if j>=k-1:
            if l[j-k+1]=='D':
                dm-=m
                d-=1
            elif l[j-k+1]=='M':
                m-=1
    print(ans)

# Buggy version:
e=enumerate
n,s,q,*k=open(0).read().split()
m,c,x=eval('[0]*-~int(n),'*3)
for i,t in e(s,1):
  m[i]=m[i-1]+(t=='M')
  f=t=='C'
  c[i]=c[i-1]+f
  x[i]=x[i-1]+f*m[i]
for k in map(int,k):
  a=0
  for i,t in e(s):
    j=min(n,i+k)
    if t=='D':a+=x[j]-x[i]-(c[j]-c[i])*m[i]
  print(a)

# Fixed version:
e=enumerate
n,s,q,*k=open(0).read().split()
n=int(n)
m,c,x=eval('[0]*-~n,'*3)
for i,t in e(s,1):
  m[i]=m[i-1]+(t=='M')
  f=t=='C'
  c[i]=c[i-1]+f
  x[i]=x[i-1]+f*m[i]
for k in map(int,k):
  a=0
  for i,t in e(s):
    j=min(n,i+k)
    if t=='D':
      a+=x[j]-x[i]-(c[j]-c[i])*m[i]
  print(a)

# Buggy version:
n = int(input())
s = input()
q = int(input())
k = list(map(int, input().split()))
for ki in k:
    ans = 0
    DMC = [0]*3
    for i in range(n):
        if s[i] == "D":
            DMC[0] += 1
        elif s[i] == "M":
            DMC[1] += 1
            DMC[2] += DMC[0]
        if i >= ki:
            j = i-ki
            if s[j] == "D":
                DMC[0] -= 1
                DMC[2] -= DMC[1]
            elif s[j] == "M":
                DMC[1] -= 1
        if c == "C":
            ans += DMC[2]
    print(ans)

# Fixed version:
n = int(input())
s = input()
q = int(input())
k = list(map(int, input().split()))
for ki in k:
    ans = 0
    DMC = [0]*3
    #for i, c in enumerate(s):
    for i in range(n):
        if s[i] == "D":
            DMC[0] += 1
        elif s[i] == "M":
            DMC[1] += 1
            DMC[2] += DMC[0]
        if i >= ki:
            j = i-ki
            if s[j] == "D":
                DMC[0] -= 1
                DMC[2] -= DMC[1]
            elif s[j] == "M":
                DMC[1] -= 1
        if s[i] == "C":
            ans += DMC[2]
    print(ans)

# Buggy version:
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))

# Fixed version:
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))

# Buggy version:
n = int(input())
s = input()
acc_cnt_a = [0] * n
acc_cnt_b = [0] * n
acc_cnt_ab = [0] * n
c_loc = []
cnt_a = 0
cnt_b = 0
cnt_ab = 0
for i, c in enumerate(s):
    if c == 'D':
        cnt_a += 1
    elif c == 'M':
        cnt_b += 1
        cnt_ab += cnt_a
    elif c == 'C':
        c_loc.append(i)
    acc_cnt_a[i] = cnt_a
    acc_cnt_b[i] = cnt_b
    acc_cnt_ab[i] = cnt_ab

q = int(input())
buf = []
for k in map(int, input().split()):
    ans = 0
    for r in c_loc:
        l = r - k
        if l > 0:
            rejected_a = acc_cnt_a[l]
            cnt_internal_b = acc_cnt_b[r] - acc_cnt_b[l]
            cnt_internal_ab = acc_cnt_ab[r] - acc_cnt_ab[l]
            ans += cnt_internal_ab - rejected_a * cnt_internal_b
        else:
            ans += acc_cnt_ab[r]
    buf.append(ans)
print('\n'.join(map(str, buf)))


# Fixed version:
n = int(input())
s = input()
acc_cnt_a = [0] * (n + 1)
acc_cnt_b = [0] * (n + 1)
acc_cnt_ab = [0] * (n + 1)
c_loc = []
cnt_a = 0
cnt_b = 0
cnt_ab = 0
for i, c in enumerate(s):
    if c == 'D':
        cnt_a += 1
    elif c == 'M':
        cnt_b += 1
        cnt_ab += cnt_a
    elif c == 'C':
        c_loc.append(i + 1)
    acc_cnt_a[i + 1] = cnt_a
    acc_cnt_b[i + 1] = cnt_b
    acc_cnt_ab[i + 1] = cnt_ab

q = int(input())
buf = []
for k in map(int, input().split()):
    ans = 0
    for r in c_loc:
        l = r - k
        if l > 0:
            rejected_a = acc_cnt_a[l]
            cnt_internal_b = acc_cnt_b[r] - acc_cnt_b[l]
            cnt_internal_ab = acc_cnt_ab[r] - acc_cnt_ab[l]
            ans += cnt_internal_ab - rejected_a * cnt_internal_b
        else:
            ans += acc_cnt_ab[r]
    buf.append(ans)
print('\n'.join(map(str, buf)))