Language: C++

#include <bits/stdc++.h>

using namespace std;
#define ll long long

#define rep(i, a) for (int (i) = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int (i) = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int (i) = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int (i) = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define TRUE__ "Yes"
#define FALSE__ "No"
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x

#define int ll

void init();
void solve();

signed main()
{
	init();
	solve();
}

int N, Q;
string s;
vector<int> K;

void init()
{
	cin >> N >> s >> Q;
	K.resize(Q);
	rep(i, Q) cin >> K[i];
}

int calc(int k)
{
	int d = 0, m = 0;
	int dm = 0;
	int st = 0;
	int en = 1;
	int res = 0;
	if (s[0] == 'D') d++;
	if (s[0] == 'M') m++;
	while (en < N) {
		if (s[en] == 'C') {
			res += dm;
		} else if (s[en] == 'D') {
			d++;
		} else if (s[en] == 'M') {
			m++;
			dm += d;
		}
		en++;
		st = max(0, en - k + 1);
		if (st) {
			if (s[st-1] == 'D') {
				d--;
				dm -= m;
			} else if (s[st-1] == 'M') {
				m--;
			}
		}
	}
	return res;
}

void solve()
{
	rep(i, Q) {
		cout << calc(K[i]) << endl;
	}
}


Compiler output:
a.cc: In function 'long long int calc(long long int)':
a.cc:61:25: error: no matching function for call to 'max(int, long long int)'
   61 |                 st = max(0, en - k + 1);
      |                      ~~~^~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/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:61:25: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   61 |                 st = max(0, en - k + 1);
      |                      ~~~^~~~~~~~~~~~~~~
/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:
/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:61:25: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   61 |                 st = max(0, en - k + 1);
      |                      ~~~^~~~~~~~~~~~~~~