//Δ_C
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<bitset>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
const int N = 1e6+16;
char s[N];
int n,q,k,a[N];
void solve(){
	int i;
	LL x=0,y=0,z=0;
	for(i=1;i<=n;i=i+1){
		if(i>=k){
			if(s[i-k]=='D')
				x--,y-=a[i-1]-a[i-k];
		}
		if(s[i]=='D')
			x++;
		if(s[i]=='M')
			y+=x;
		if(s[i]=='C')
			z+=y;
	}
	cout<<z<<endl;
}
int main()
{
	int i;
	scanf("%d%s%d",&n,s+1,&q);
	for(i=1;i<=n;i=i+1)
		a[i]=a[i-1]+(s[i]=='M');
	while(q--){
		scanf("%d",&k);
		solve();
	}
	return 0;
}