Language: C++

#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
int max(int a,int b){return (a>b ? a:b);}
int min(int a,int b){return (a<b ? a:b);}
int compare_int(const void *a, const void *b){return *(int*)a - *(int*)b;}
//qsort(配列, 長さ, sizeof(int), compare_int);
double BS(int array[],int len,int target);

//////////////////////////////////////////
int N,Q;
char blank;
char S[200010],t[200010],d[200010];

int zero1(){
    for(int i = 0;i < Q;i++){
        if(d[i]=='L' && t[i]==S[1]) return 1;
    }
    return 0;
}
int nibun1(int n,int M){
    //printf("%d\n",M-n);
    int new = (M+n+1)/2;
    int g = new;
    for(int i = 0;i < Q;i++){
        if(d[i]=='R' && t[i]==S[g] && g>0 && g<N+1)g++;
        if(d[i]=='L' && t[i]==S[g] && g>0 && g<N+1)g--;
    }
    if(g != 0 && M-n <= 1)return n;
    if(g == 0 && M-n <= 1)return M;
    if(g != 0)return nibun1(n,(new+M)/2);
    if(g == 0)return nibun1((n+new+1)/2,M);
}
int zero2(){
    for(int i = 0;i < Q;i++){
        if(d[i]=='R' && t[i]==S[N]) return 1;
    }
    return 0;
}
int nibun2(int n,int M){
    //printf("%d\n",M-n);
    int new = (M+n)/2;
    int g = new;
    for(int i = 0;i < Q;i++){
        if(d[i]=='R' && t[i]==S[g] && g>0 && g<N+1)g++;
        if(d[i]=='L' && t[i]==S[g] && g>0 && g<N+1)g--;
    }
    if(g != N+1 && M-n <= 1)return M;
    if(g == N+1 && M-n <= 1)return n;
    if(g != N+1)return nibun2((n+new+1)/2,M);
    if(g == N+1)return nibun2(n,(new+M)/2);
}

///////////////////////////////////
int main(){
    scanf("%d%d",&N,&Q);
    scanf("%s",S);
    for(int i = 0;i < Q;i++){
        scanf("%c%c%c%c",&blank,&t[i],&blank,&d[i]);
    }
    for(int i = N;i > 0;i--){
        S[i] = S[i-1];
    }


    int count = N;
    if(zero1()){
        count -= nibun1(1,N);
        //printf("%d\n",count);
    }
    if(zero2()){
        count -= N - nibun2(1,N) + 1;
        //printf("%d\n",count);
    }
    printf("%d\n",count);
    return 0;
}


///////////////////////////////////////////


double BS(int array[],int len,int target){ //(配列,長さ,見つける値)
    int low,mid,high;

    low = 0;
    high = len-1;

    int mark;

    while(low <= high){
        mid = (low + high) / 2;
        if(array[mid] == target){
            mark = 0;
            break;
        }else if(array[mid] < target){
            low = mid + 1;
            mark = 1;
        }else{
            high = mid - 1;
            mark = -1;
        }
    }
    if(mark == 0){
        return mid; //配列の何番目か（０から）
    }else if(mark == 1){
        return (double)mid + 0.5;//なかったらどこのあいだか
    }else{
        return (double)mid - 0.5;
    }
}


Compiler output:
a.cc: In function 'int nibun1(int, int)':
a.cc:24:9: error: expected unqualified-id before 'new'
   24 |     int new = (M+n+1)/2;
      |         ^~~
a.cc:25:16: error: expected type-specifier before ';' token
   25 |     int g = new;
      |                ^
a.cc:32:35: error: expected type-specifier before '+' token
   32 |     if(g != 0)return nibun1(n,(new+M)/2);
      |                                   ^
a.cc:33:35: error: expected type-specifier before '+' token
   33 |     if(g == 0)return nibun1((n+new+1)/2,M);
      |                                   ^
a.cc: In function 'int nibun2(int, int)':
a.cc:43:9: error: expected unqualified-id before 'new'
   43 |     int new = (M+n)/2;
      |         ^~~
a.cc:44:16: error: expected type-specifier before ';' token
   44 |     int g = new;
      |                ^
a.cc:51:37: error: expected type-specifier before '+' token
   51 |     if(g != N+1)return nibun2((n+new+1)/2,M);
      |                                     ^
a.cc:52:37: error: expected type-specifier before '+' token
   52 |     if(g == N+1)return nibun2(n,(new+M)/2);
      |                                     ^