Language: C++

#include<iostream>
#include<sstream>
#include<vector>
#include<map>
#include<algorithm>
#include<random>
#include<string>
#include<queue>
#include<math.h>

using namespace std;

#define int long long
#define double long double

template<typename T>
T get() {
	T a; cin >> a; return a;
}

template<typename T>
void prv(vector<T> const& vec, string space) {
	for (auto const& e : vec) {
		cout << e << space;
	}
	cout << endl;
}

template<typename T>
void prvv(vector<vector<T>> const& vec, string space, string line) {
	for (auto const& list : vec) {
		for (auto const& e : list) {
			cout << e << space;
		}
		cout << line;
	}
}

#define loop(x, n, m) for(int x = n; x < m; x++)
#define aloop(x, n, m) for(int x = m - 1; x >= n; x--)
#define dloop(x, n, m, t) for(int x = n; x < m; x+=t)
#define read(str) cin >> str
#define deb(str) cout << str << " "
#define det(str) cout << str
#define dbl(str) cout << str << "\n"
#define spc << " " <<
#define tab << "\t" <<
#define tb << "\t"
#define tabw cout << "\t"
#define el cout << "\n"
#define gi() get<int>()
#define gs() get<string>()
#define gf() get<float>()
#define wait() int a; cin >> a;
#define priv(vec) prv<int>(vec, " ")
#define prsv(vec) prv<string>(vec, " ")
#define privv(vec) prvv<int>(vec, " ", "\t")
#define prsvv(vec) prvv<string>(vec, " ", "\t")
#define prtv(T, vec, space) prv<T>(vec, space)
#define prtvv(T, vec, space, line) prvv<T>(vec, space, line)
#define vec vector

signed main() {
	/*cin.tie(0);
	ios_base::sync_with_stdio(false);*/

	int N = gi(), Q = gi();
	string word = gs();
	vec<int> letters;
	vec<int> squares(N, 1), indecies;
	vec<bool> left;
		
	loop (i, 0, word.size()) {
		letters.push_back(word[i] - 'A');
	}

	loop(i, 0, Q) {
		string a, b;
		cin >> a >> b;

		indecies.push_back(a[0] - 'A');
		left.push_back((b[0] == 'L') ? true : false);
	}

	int current_index_left = -1, last_time = 0;
	aloop(i, 0, Q) {
		if (current_index_left + 1 >= N) break;
		if (indecies[i] == letters[current_index_left + 1] && left[i] == true) {
			last_time = i;
			current_index_left++;
		}
	}
	int current_minus_left = min(current_index_left + 1, N - 1);
	aloop(i, 0, last_time) {
		if (current_minus_left - 1 < 0) break;
		if (indecies[i] == letters[current_minus_left - 1] && left[i] == false) {
			current_minus_left--;
		}
	}

	int current_index_right = N;
	last_time = 0;
	aloop(i, 0, Q) {
		if (current_index_left -1 < 0) break;
		if (indecies[i] == letters[current_index_right - 1] && left[i] == false) {
			current_index_right--;
			last_time = i;
		}

	}
	int current_minus_right = max(current_index_right - 1, int(0));
	aloop(i, 0, last_time) {
		if (current_minus_right + 1 >= N) break;
		if (indecies[i] == letters[current_minus_right + 1] && left[i] == true) {
			current_minus_right++;
		}
	}

	dbl(current_index_left spc current_minus_left spc current_index_right spc current_minus_right);
	dbl(N - (max(int(0), current_minus_left - 1) + N - min(current_minus_right + 1, N)));

	//dbl(N);

	wait();
}

Compiler output:
a.cc: In function 'int main()':
a.cc:13:13: error: expected primary-expression before 'long'
   13 | #define int long long
      |             ^~~~
a.cc:111:64: note: in expansion of macro 'int'
  111 |         int current_minus_right = max(current_index_right - 1, int(0));
      |                                                                ^~~
a.cc:13:13: error: expected primary-expression before 'long'
   13 | #define int long long
      |             ^~~~
a.cc:45:26: note: in definition of macro 'dbl'
   45 | #define dbl(str) cout << str << "\n"
      |                          ^~~
a.cc:120:22: note: in expansion of macro 'int'
  120 |         dbl(N - (max(int(0), current_minus_left - 1) + N - min(current_minus_right + 1, N)));
      |                      ^~~