Language: C++

#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct move
{
    char ch, direction;

    move(){}

    move(char C, char D)
    {
        ch = C, direction = D;
    }
};

int displacement(string &S, int position, vector <move> &M)
{ //cout << position << " final = ";
    for(int i = 1; i < M.size(); i++)
    {
        if(S[position] == M[i].ch)
        {
            position += (M[i].direction == 'L' ? -1 : 1);
        }

        if(position == 0 || position == S.size() - 1)
        {
            break;
        }
    }// cout << position << endl;

    return position;
}

int main()
{
    int length, no_of_moves;
    string S;
    cin >> length >> no_of_moves >> S;

    S = '*' + S + '*';

    vector <move> moves(no_of_moves + 1);
    for(int i = 1; i <= no_of_moves; i++)
    {
        cin >> moves[i].ch >> moves[i].direction;
    }

    int left = 0, right = length + 1;
    while(right - left > 1)
    {
        int mid = (left + right)/2;

        if(displacement(S, mid, moves) == 0)
        {
            left = mid;
        }
        else
        {
            right = mid;
        }
    }
    int rightmost_to_fall_left = left; //cout << "R = " << rightmost_to_fall_left << endl;

    left = 0, right = length;
    while(right - left > 1)
    {
        int mid = (left + right)/2;

        if(displacement(S, mid, moves) == length + 1)
        {
            right = mid;
        }
        else
        {
            left = mid;
        }
    }
    int leftmost_to_fall_right = right; //cout << "L = " << leftmost_to_fall_right << endl;

    int remaining = (leftmost_to_fall_right - 1) - rightmost_to_fall_left;
    cout << remaining;

    return 0;
}


Compiler output:
a.cc:19:55: error: template argument 1 is invalid
   19 | int displacement(string &S, int position, vector <move> &M)
      |                                                       ^
a.cc:19:55: error: template argument 2 is invalid
a.cc:19:55: error: template argument 1 is invalid
a.cc:19:55: error: template argument 2 is invalid
a.cc:19:55: error: template argument 1 is invalid
a.cc:19:55: error: template argument 2 is invalid
a.cc:19:43: error: invalid template-id
   19 | int displacement(string &S, int position, vector <move> &M)
      |                                           ^~~~~~
a.cc:19:51: error: reference to 'move' is ambiguous
   19 | int displacement(string &S, int position, vector <move> &M)
      |                                                   ^~~~
In file included from /usr/include/c++/14/string:51,
                 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/stl_algobase.h:675:5: note: candidates are: 'template<class _II, class _OI> _OI std::move(_II, _II, _OI)'
  675 |     move(_II __first, _II __last, _OI __result)
      |     ^~~~
In file included from /usr/include/c++/14/bits/exception_ptr.h:41,
                 from /usr/include/c++/14/exception:166,
                 from /usr/include/c++/14/ios:41:
/usr/include/c++/14/bits/move.h:137:5: note:                 'template<class _Tp> constexpr typename std::remove_reference<_Tp>::type&& std::move(_Tp&&)'
  137 |     move(_Tp&& __t) noexcept
      |     ^~~~
a.cc:7:8: note:                 'struct move'
    7 | struct move
      |        ^~~~
a.cc:19:43: error: missing template argument list after 'std::vector'; template placeholder not permitted in parameter
   19 | int displacement(string &S, int position, vector <move> &M)
      |                                           ^~~~~~
      |                                                 <>
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_vector.h:428:11: note: 'template<class _Tp, class _Alloc> class std::vector' declared here
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
a.cc: In function 'int displacement(...)':
a.cc:21:24: error: 'M' was not declared in this scope
   21 |     for(int i = 1; i < M.size(); i++)
      |                        ^
a.cc: In function 'int main()':
a.cc:45:17: error: template argument 1 is invalid
   45 |     vector <move> moves(no_of_moves + 1);
      |                 ^
a.cc:45:17: error: template argument 2 is invalid
a.cc:48:21: error: invalid types 'int[int]' for array subscript
   48 |         cin >> moves[i].ch >> moves[i].direction;
      |                     ^
a.cc:48:36: error: invalid types 'int[int]' for array subscript
   48 |         cin >> moves[i].ch >> moves[i].direction;
      |                                    ^