Language: C++

#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int n,q;//nはマスの数で、qは唱える呪文の回数
int main(){
    //入力
    cin >> n >> q;
    string s;
    cin >> s;
    vector<char>t(q),d(q);//tはアルファベットで、dは左右を表す
    for(int i=0; i<q;i++)
    {
        cin >> t[i] >> d[i];
    }

    //処理
    /*考え方：最終的に何体のロボットが残っているかを考える。探す際は二分探索を用いる
    1.
    */
   int left=-1; right=n;
   for(int i=q-1; i>=0;i--)
   {
       if(d[i]=='L' and t[i]==s[left+1])left++;
       if(d[i]=='R' and t[i]==s[right-1])right++;
       if(d[i]=='L' and t[i]==s[right])right++;
       if(d[i]=='R' and t[i]==s[left])left++;
   }

   //出力
   cout << max(0,right-left-1) << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:23:22: error: assignment of function 'std::ios_base& std::right(ios_base&)'
   23 |    int left=-1; right=n;
      |                 ~~~~~^~
a.cc:27:38: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   27 |        if(d[i]=='R' and t[i]==s[right-1])right++;
      |                                 ~~~~~^~
a.cc:27:38: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-fpermissive]
   27 |        if(d[i]=='R' and t[i]==s[right-1])right++;
      |                                 ~~~~~^~
      |                                      |
      |                                      std::ios_base& (*)(std::ios_base&)
In file included from /usr/include/c++/14/string:54,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/basic_string.h:1265:28: note:   initializing argument 1 of 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&; size_type = long unsigned int]'
 1265 |       operator[](size_type __pos)
      |                  ~~~~~~~~~~^~~~~
a.cc:27:42: warning: ISO C++ forbids incrementing a pointer of type 'std::ios_base& (*)(std::ios_base&)' [-Wpointer-arith]
   27 |        if(d[i]=='R' and t[i]==s[right-1])right++;
      |                                          ^~~~~
a.cc:27:47: error: lvalue required as increment operand
   27 |        if(d[i]=='R' and t[i]==s[right-1])right++;
      |                                               ^~
a.cc:28:33: error: invalid conversion from 'std::ios_base& (*)(std::ios_base&)' to 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-fpermissive]
   28 |        if(d[i]=='L' and t[i]==s[right])right++;
      |                                 ^~~~~
      |                                 |
      |                                 std::ios_base& (*)(std::ios_base&)
/usr/include/c++/14/bits/basic_string.h:1265:28: note:   initializing argument 1 of 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](size_type) [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; reference = char&; size_type = long unsigned int]'
 1265 |       operator[](size_type __pos)
      |                  ~~~~~~~~~~^~~~~
a.cc:28:40: warning: ISO C++ forbids incrementing a pointer of type 'std::ios_base& (*)(std::ios_base&)' [-Wpointer-arith]
   28 |        if(d[i]=='L' and t[i]==s[right])right++;
      |                                        ^~~~~
a.cc:28:45: error: lvalue required as increment operand
   28 |        if(d[i]=='L' and t[i]==s[right])right++;
      |                                             ^~
a.cc:33:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   33 |    cout << max(0,right-left-1) << endl;
      |                  ~~~~~^~~~~
a.cc:33:28: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   33 |    cout << max(0,right-left-1) << endl;
      |                  ~~~~~~~~~~^~
a.cc:33:15: error: no matching function for call to 'max(int, std::ios_base& (*)(std::ios_base&))'
   33 |    cout << max(0,right-left-1) << endl;
      |            ~~~^~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51:
/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:33:15: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'std::ios_base& (*)(std::ios_base&)')
   33 |    cout << max(0,right-left-1) << endl;
      |            ~~~^~~~~~~~~~~~~~~~
/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:4:
/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:33:15: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   33 |    cout << max(0,right-left-1) << endl;
      |            ~~~^~~~~~~~~~~~~~~~