Language: C++

//minamoto
#include<bits/stdc++.h>
#define R register
#define fp(i,a,b) for(R int i=(a),I=(b)+1;i<I;++i)
#define fd(i,a,b) for(R int i=(a),I=(b)-1;i>I;--i)
#define go(u) for(int i=head[u],v=e[i].v;i;i=e[i].nx,v=e[i].v)
template<class T>inline bool cmax(T&a,const T&b){return a<b?a=b,1:0;}
template<class T>inline bool cmin(T&a,const T&b){return a>b?a=b,1:0;}
using namespace std;
const int N=1e5+10;
namespace MAIN{
    int n,k;
    char str[N];
    int ans;
    Pair a[2][N];
    int b[2];
    int st,ed;
    inline void MAIN(){
        n=read(),k=read(),scanf("%s",str+1);
        for(res i=1;i<=n;){
            res j=i;
            while(str[j]==str[i]&&j<=n)j++;
            j--;
            if(str[i]=='L')a[0][++b[0]]=mp(i,j);
            else a[1][++b[1]]=mp(i,j);
            i=j+1;
        }
        st=str[1]=='R';
        ed=str[n]=='R';
        for(res i=1;i<=b[0];i++)ans+=a[0][i].se-a[0][i].fi;
        for(res i=1;i<=b[1];i++)ans+=a[1][i].se-a[1][i].fi;
        if(b[0]<=k){printf("%d\n",n-1);return;}
        if(b[1]<=k){printf("%d\n",n-1);return;}
        if(st==ed){
            printf("%d\n",ans+2*k);
            return;
        }
        printf("%d\n",ans+2*k);
    }
}
int main(){
    MAIN::MAIN();
    return 0;
}

Compiler output:
a.cc:15:5: error: 'Pair' does not name a type
   15 |     Pair a[2][N];
      |     ^~~~
a.cc: In function 'void MAIN::MAIN()':
a.cc:19:15: error: too few arguments to function 'ssize_t read(int, void*, size_t)'
   19 |         n=read(),k=read(),scanf("%s",str+1);
      |           ~~~~^~
In file included from /usr/include/x86_64-linux-gnu/bits/sigstksz.h:24,
                 from /usr/include/signal.h:328,
                 from /usr/include/c++/14/csignal:42,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:116,
                 from a.cc:2:
/usr/include/unistd.h:371:16: note: declared here
  371 | extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
      |                ^~~~
a.cc:19:24: error: too few arguments to function 'ssize_t read(int, void*, size_t)'
   19 |         n=read(),k=read(),scanf("%s",str+1);
      |                    ~~~~^~
/usr/include/unistd.h:371:16: note: declared here
  371 | extern ssize_t read (int __fd, void *__buf, size_t __nbytes) __wur
      |                ^~~~
a.cc:20:13: error: 'res' was not declared in this scope
   20 |         for(res i=1;i<=n;){
      |             ^~~
a.cc:20:21: error: 'i' was not declared in this scope
   20 |         for(res i=1;i<=n;){
      |                     ^
a.cc:21:16: error: expected ';' before 'j'
   21 |             res j=i;
      |                ^~
      |                ;
a.cc:22:23: error: 'j' was not declared in this scope
   22 |             while(str[j]==str[i]&&j<=n)j++;
      |                       ^
a.cc:23:13: error: 'j' was not declared in this scope
   23 |             j--;
      |             ^
a.cc:24:28: error: 'a' was not declared in this scope
   24 |             if(str[i]=='L')a[0][++b[0]]=mp(i,j);
      |                            ^
a.cc:24:41: error: 'mp' was not declared in this scope; did you mean 'fp'?
   24 |             if(str[i]=='L')a[0][++b[0]]=mp(i,j);
      |                                         ^~
      |                                         fp
a.cc:25:18: error: 'a' was not declared in this scope
   25 |             else a[1][++b[1]]=mp(i,j);
      |                  ^
a.cc:25:31: error: 'mp' was not declared in this scope; did you mean 'fp'?
   25 |             else a[1][++b[1]]=mp(i,j);
      |                               ^~
      |                               fp
a.cc:30:13: error: 'res' was not declared in this scope
   30 |         for(res i=1;i<=b[0];i++)ans+=a[0][i].se-a[0][i].fi;
      |             ^~~
a.cc:30:21: error: 'i' was not declared in this scope
   30 |         for(res i=1;i<=b[0];i++)ans+=a[0][i].se-a[0][i].fi;
      |                     ^
a.cc:30:38: error: 'a' was not declared in this scope
   30 |         for(res i=1;i<=b[0];i++)ans+=a[0][i].se-a[0][i].fi;
      |                                      ^
a.cc:31:13: error: 'res' was not declared in this scope
   31 |         for(res i=1;i<=b[1];i++)ans+=a[1][i].se-a[1][i].fi;
      |             ^~~
a.cc:31:21: error: 'i' was not declared in this scope
   31 |         for(res i=1;i<=b[1];i++)ans+=a[1][i].se-a[1][i].fi;
      |                     ^
a.cc:31:38: error: 'a' was not declared in this scope
   31 |         for(res i=1;i<=b[1];i++)ans+=a[1][i].se-a[1][i].fi;
      |                                      ^