Language: C++

#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "\n" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	string S;
	cin >> S;
	vector<int> D, M, C;
	vector<int> C_cnt(N);
	for (int i = 0; i < N; i++) {
		if (S[i] == 'D') D.emplace_back(i);
		if (S[i] == 'M') M.emplace_back(i);
		if (S[i] == 'C') {
			C.emplace_back(i);
			C_cnt[i] = 1;
		}
	}
	for (int i = 0; i < N - 1; i++) C_cnt[i + 1] += C_cnt[i];
	vector<int> MC_cnt(M.size());
	for (int i = 0; i < M.size(); i++) MC_cnt[i] = C_cnt[M[i]];

	DMP(D, M, C);

	auto query = [&](int k) {
		
		lint res = 0;
		queue<pair<int,int>> M_q;
		int M_i = 0;
		lint MC = 0;
		for (int i = 0; i < D.size(); i++) {

			while (M_i < M.size() && D[i] < M[M_i] && D[i] + k > M[M_i]) {
				M_q.emplace(M[M_i], M_i);
				MC += MC_cnt[M_i];
				M_i++;
			}

			while (!M_q.empty() && D[i] > M_q.front().first) {
				MC -= MC_cnt[M_q.front().second];
				M_q.pop();
			}

			res += max(M_q.size() * C_cnt[min(D[i] + k - 1, N - 1)] - MC, 0);

		}

		return res;

	};

	int Q;
	cin >> Q;

	for (int i = 0; i < Q; i++) {
		int k;
		cin >> k;
		cout << query(k) << "\n";
	}

	return 0;
}

Compiler output:
a.cc: In lambda function:
a.cc:83:35: error: no matching function for call to 'max(long long unsigned int, int)'
   83 |                         res += max(M_q.size() * C_cnt[min(D[i] + k - 1, N - 1)] - MC, 0);
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/bits/specfun.h:43,
                 from /usr/include/c++/14/cmath:3906,
                 from a.cc:3:
/usr/include/c++/14/bits/stl_algobase.h:257:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:   template argument deduction/substitution failed:
a.cc:83:35: note:   deduced conflicting types for parameter 'const _Tp' ('long long unsigned int' and 'int')
   83 |                         res += max(M_q.size() * C_cnt[min(D[i] + k - 1, N - 1)] - MC, 0);
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:12:
/usr/include/c++/14/bits/stl_algo.h:5706:5: note: candidate: 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note:   template argument deduction/substitution failed:
a.cc:83:35: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long unsigned int'
   83 |                         res += max(M_q.size() * C_cnt[min(D[i] + k - 1, N - 1)] - MC, 0);
      |                                ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~