Language: C++

#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
 //   freopen("input.txt","r",stdin);
 //   freopen("output.txt","w",stdout);
    
    int n,q;
    cin>>n>>q;
    string s;
    cin>>s;
    string c,d;
    c ="";
    d ="";
    for(int i=0;i<q;i++)
    {
        char cc,dd;
        cin>>cc>>dd;
        c+=cc;
        d+=dd;
    }
    int l=-1,r=n;
    int mid = l+((r-l)/2);
    int l_max=-1;
    for(int i=0;i<80;i++)
    {
        if(l+1<r)
        {
            mid = l+((r-l)/2);
            char val = s[mid];
            bool reached = false;
            for(int j=0;j<q;j++)
            {
                if(c[j]==val&&d[j]=='L')
                {
                    index--;
                }
                else if(c[j]==val&&d[j]=='R')
                {
                    index++;
                }
                if(index ==-1)
                {
                    reached=true;
                    break;
                }
                else if (index ==n)
                    break;
                val = s[index];      
            }
            if(reached)
            {
                l = mid;
                l_max = mid;
            }
            else
                r = mid;
        }
        else
        {
            break;
        }
    }

    l=-1,r=n;
    mid = l+((r-l)/2);
    int r_max=n;
    for(int i=0;i<80;i++)
    {
        if(l+1<r)
        {
            mid = l+((r-l)/2);
            int index= mid;
            char val = s[index];
            bool reached = false;
            for(int j=0;j<q;j++)
            {
                if(c[j]==val&&d[j]=='L')
                {
                    index--;

                }
                else if(c[j]==val&&d[j]=='R')
                {
                    index++;
                }
                if(index == n)
                {
                    reached=true;
                    break;
                }      
                else if (index ==-1)
                    break;
                val = s[index];      
            }
            if(reached)
            {
                r = mid;
                r_max = mid;
            }
            else
                l = mid+1;
        }
        else
        {
            break;
        }
    }
    l_max++;
    r_max--;

    cout<<max(0,r_max-l_max+1);
    return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:69:26: error: no post-decrement operator for type
   69 |                     index--;
      |                          ^~
a.cc:73:26: error: no post-increment operator for type
   73 |                     index++;
      |                          ^~
a.cc:75:26: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator=='
   75 |                 if(index ==-1)
      |                    ~~~~~~^~~~
a.cc:80:32: error: invalid operands of types '<unresolved overloaded function type>' and 'int' to binary 'operator=='
   80 |                 else if (index ==n)
      |                          ~~~~~~^~~
a.cc:82:24: error: no match for 'operator[]' (operand types are 'std::string' {aka 'std::__cxx11::basic_string<char>'} and '<unresolved overloaded function type>')
   82 |                 val = s[index];
      |                        ^
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:1247:7: note: candidate: 'std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::const_reference std::__cxx11::basic_string<_CharT, _Traits, _Alloc>::operator[](size_type) const [with _CharT = char; _Traits = std::char_traits<char>; _Alloc = std::allocator<char>; const_reference = const char&; size_type = long unsigned int]'
 1247 |       operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:1247:29: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'}
 1247 |       operator[] (size_type __pos) const _GLIBCXX_NOEXCEPT
      |                   ~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/basic_string.h:1265:7: note: candidate: '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)
      |       ^~~~~~~~
/usr/include/c++/14/bits/basic_string.h:1265:28: note:   no known conversion for argument 1 from '<unresolved overloaded function type>' to 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'}
 1265 |       operator[](size_type __pos)
      |                  ~~~~~~~~~~^~~~~