Language: C++

#include <bits/stdc++.h>
#define long long unsigned long long
using namespace std;

string s;
long long n, q, k;
long long cnt[1000005][2] = {0};

long long solve();

int main() {
  cin >> n >> s >> q;
  for(long long i = 0; i < n; ++i) {
    if(i != 0) {
      cnt[i][0] = cnt[i - 1][0];
      cnt[i][1] = cnt[i - 1][1];
    }
    if(s[i] == 'D') ++cnt[i][0];
    if(s[i] == 'M') ++cnt[i][1];
  }
  for(long long i = 0; i < q; ++i) {
    cin >> k;
    cout << solve() << endl;
  }
  return 0;
}
long long solve() {
  long long now = 0, ans = 0;
  for(long long i = 0; i < n; ++i) {
    if(i >= k && s[i - k] == 'D') {
      if(i != 0) now -= cnt[i - 1][1];
      now += cnt[i - k][1];
    }
    if(s[i] == 'M') {
      if(i != 0) now += cnt[i - 1][0];
      if(i >= k) now -= cnt[i - k][0];
    }
    if(s[i] == 'C') ans += now;
  }
  return ans;
}


Compiler output:
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:6:1: note: in expansion of macro 'long'
    6 | long long n, q, k;
      | ^~~~
a.cc:2:14: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |              ^~~~
a.cc:6:6: note: in expansion of macro 'long'
    6 | long long n, q, k;
      |      ^~~~
a.cc:2:19: error: duplicate 'unsigned'
    2 | #define long long unsigned long long
      |                   ^~~~~~~~
a.cc:6:6: note: in expansion of macro 'long'
    6 | long long n, q, k;
      |      ^~~~
a.cc:2:28: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                            ^~~~
a.cc:6:6: note: in expansion of macro 'long'
    6 | long long n, q, k;
      |      ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:6:6: note: in expansion of macro 'long'
    6 | long long n, q, k;
      |      ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:7:1: note: in expansion of macro 'long'
    7 | long long cnt[1000005][2] = {0};
      | ^~~~
a.cc:2:14: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |              ^~~~
a.cc:7:6: note: in expansion of macro 'long'
    7 | long long cnt[1000005][2] = {0};
      |      ^~~~
a.cc:2:19: error: duplicate 'unsigned'
    2 | #define long long unsigned long long
      |                   ^~~~~~~~
a.cc:7:6: note: in expansion of macro 'long'
    7 | long long cnt[1000005][2] = {0};
      |      ^~~~
a.cc:2:28: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                            ^~~~
a.cc:7:6: note: in expansion of macro 'long'
    7 | long long cnt[1000005][2] = {0};
      |      ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:7:6: note: in expansion of macro 'long'
    7 | long long cnt[1000005][2] = {0};
      |      ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:9:1: note: in expansion of macro 'long'
    9 | long long solve();
      | ^~~~
a.cc:2:14: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |              ^~~~
a.cc:9:6: note: in expansion of macro 'long'
    9 | long long solve();
      |      ^~~~
a.cc:2:19: error: duplicate 'unsigned'
    2 | #define long long unsigned long long
      |                   ^~~~~~~~
a.cc:9:6: note: in expansion of macro 'long'
    9 | long long solve();
      |      ^~~~
a.cc:2:28: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                            ^~~~
a.cc:9:6: note: in expansion of macro 'long'
    9 | long long solve();
      |      ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:9:6: note: in expansion of macro 'long'
    9 | long long solve();
      |      ^~~~
a.cc: In function 'int main()':
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:13:7: note: in expansion of macro 'long'
   13 |   for(long long i = 0; i < n; ++i) {
      |       ^~~~
a.cc:2:14: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |              ^~~~
a.cc:13:12: note: in expansion of macro 'long'
   13 |   for(long long i = 0; i < n; ++i) {
      |            ^~~~
a.cc:2:19: error: duplicate 'unsigned'
    2 | #define long long unsigned long long
      |                   ^~~~~~~~
a.cc:13:12: note: in expansion of macro 'long'
   13 |   for(long long i = 0; i < n; ++i) {
      |            ^~~~
a.cc:2:28: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                            ^~~~
a.cc:13:12: note: in expansion of macro 'long'
   13 |   for(long long i = 0; i < n; ++i) {
      |            ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:13:12: note: in expansion of macro 'long'
   13 |   for(long long i = 0; i < n; ++i) {
      |            ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:21:7: note: in expansion of macro 'long'
   21 |   for(long long i = 0; i < q; ++i) {
      |       ^~~~
a.cc:2:14: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |              ^~~~
a.cc:21:12: note: in expansion of macro 'long'
   21 |   for(long long i = 0; i < q; ++i) {
      |            ^~~~
a.cc:2:19: error: duplicate 'unsigned'
    2 | #define long long unsigned long long
      |                   ^~~~~~~~
a.cc:21:12: note: in expansion of macro 'long'
   21 |   for(long long i = 0; i < q; ++i) {
      |            ^~~~
a.cc:2:28: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                            ^~~~
a.cc:21:12: note: in expansion of macro 'long'
   21 |   for(long long i = 0; i < q; ++i) {
      |            ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:21:12: note: in expansion of macro 'long'
   21 |   for(long long i = 0; i < q; ++i) {
      |            ^~~~
a.cc: At global scope:
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:27:1: note: in expansion of macro 'long'
   27 | long long solve() {
      | ^~~~
a.cc:2:14: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |              ^~~~
a.cc:27:6: note: in expansion of macro 'long'
   27 | long long solve() {
      |      ^~~~
a.cc:2:19: error: duplicate 'unsigned'
    2 | #define long long unsigned long long
      |                   ^~~~~~~~
a.cc:27:6: note: in expansion of macro 'long'
   27 | long long solve() {
      |      ^~~~
a.cc:2:28: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                            ^~~~
a.cc:27:6: note: in expansion of macro 'long'
   27 | long long solve() {
      |      ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:27:6: note: in expansion of macro 'long'
   27 | long long solve() {
      |      ^~~~
a.cc: In function 'long long unsigned int solve()':
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:28:3: note: in expansion of macro 'long'
   28 |   long long now = 0, ans = 0;
      |   ^~~~
a.cc:2:14: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |              ^~~~
a.cc:28:8: note: in expansion of macro 'long'
   28 |   long long now = 0, ans = 0;
      |        ^~~~
a.cc:2:19: error: duplicate 'unsigned'
    2 | #define long long unsigned long long
      |                   ^~~~~~~~
a.cc:28:8: note: in expansion of macro 'long'
   28 |   long long now = 0, ans = 0;
      |        ^~~~
a.cc:2:28: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                            ^~~~
a.cc:28:8: note: in expansion of macro 'long'
   28 |   long long now = 0, ans = 0;
      |        ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:28:8: note: in expansion of macro 'long'
   28 |   long long now = 0, ans = 0;
      |        ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:29:7: note: in expansion of macro 'long'
   29 |   for(long long i = 0; i < n; ++i) {
      |       ^~~~
a.cc:2:14: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |              ^~~~
a.cc:29:12: note: in expansion of macro 'long'
   29 |   for(long long i = 0; i < n; ++i) {
      |            ^~~~
a.cc:2:19: error: duplicate 'unsigned'
    2 | #define long long unsigned long long
      |                   ^~~~~~~~
a.cc:29:12: note: in expansion of macro 'long'
   29 |   for(long long i = 0; i < n; ++i) {
      |            ^~~~
a.cc:2:28: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                            ^~~~
a.cc:29:12: note: in expansion of macro 'long'
   29 |   for(long long i = 0; i < n; ++i) {
      |            ^~~~
a.cc:2:33: error: 'long long long' is too long for GCC
    2 | #define long long unsigned long long
      |                                 ^~~~
a.cc:29:12: note: in expansion of macro 'long'
   29 |   for(long long i = 0; i < n; ++i) {
      |            ^~~~