#include <bits/stdc++.h>
using namespace std;
unsigned long long Solve(const string& s, int n, int k) {
  deque<pair<int, int>> que;
  const char* pS = &s[0];
  unsigned long long ans = 0;
  for (int index = 0; index < n; ++index) {
    char ch = pS[index];
    while (que.size() > 0 && index - que.begin()->first >= k) {
      que.pop_front();
    }
    if (ch == 'D') {
      que.push_back(pair<int, int>(index, 0));
    } else if (ch == 'M') {
      for (auto& v : que) {
        ++v.second;
      }
    } else if (ch == 'C') {
      for (auto v : que) {
        ans += v.second;
      }
    }
  }
  return ans;
}
int main() {
  int n, q;
  string s;
  cin >> n >> s >> q;
  for (int loop = 0; loop < q; ++loop) {
    int k;
    cin >> k;
    cout << Solve(s, n, k) << endl;
  }
  return 0;
}
