Language: C++

// In the name of Allah. Ya ali!
#include<bits/stdc++.h>
#define double long double
typedef long long ll;
const ll MAX_N = 2e5+10;
const ll MOD = 1e9+7;
using namespace std;

ll dp[MAX_N];
ll sum[MAX_N];
int n,m;

ll solve(ll lim)
{
    if (n&1)
        return 0;
    lim = min(lim,n-1);
    dp[1] = 1;
    dp[3] = 1;
    sum[1] = 1;
    sum[3] = 2;
    for(int i = 5;i<=n+1;i+=2)
    {
        dp[i] = sum[i-2];
        if (i-2>lim)
            dp[i] = (dp[i]-sum[i-lim-3]+MOD)%MOD;
        sum[i] = (sum[i-2]+dp[i])%MOD;
    }
    ll ans = 0;
    ans = dp[n+1];
    for(ll i = 1;i<=lim;i+=2)
    {
        ans += (i*dp[n-i])%MOD;
        ans %= MOD;
    }
    return ans;
}

int main()
{
    cin >> n >> m;
    if (n==2)
        return cout << 2,0;
    string s;
    cin >> s;
    if (s[0]=='B')
    {
        for(int i = 0;i<m;++i)
        {
            if (s[i]=='B')
                s[i] = 'R';
            else
                s[i] = 'B';
        }
    }
    bool ok = false;
    for(int i = 0;i<m;++i)
        ok |= (s[i]=='B');
    if (!ok)
    {
        dp[1] = 1;
        dp[3] = 1;
        sum[1] = 1;
        sum[2] = 1;
        sum[3] = 2;
        for(int i = 4;i<=n+1;++i)
        {
            dp[i] = sum[i-2];
            sum[i] = (sum[i-1]+dp[i])%MOD;
        }
        ll ans = dp[n+1]+1;
        for(ll i = 1;i<n;++i)
        {
            ans += (i*dp[n-i])%MOD;
            ans %= MOD;
        }
        cout << ans;
        return 0;
    }
    for(int i = m-1;i>=0;--i)
    {
        if (s[i]=='B')
        {
            m = i+1;
            break;
        }
    }
    vector<int> vc;
    int cnt = 0;
    for(int i = 0;i<m;++i)
    {
        if (s[i]=='B')
        {
            if (cnt)
                vc.push_back(cnt);
            cnt = 0;
        }
        else
            cnt++;
    }
    ok = false;
    for(auto x:vc)
        ok |= (x&1);
    if (!ok)
        return cout << solve(vc[0]+1),0;
    int mn = 1e9;
    if (vc[0]%2==0)
        mn = vc[0]+1;
    for(auto x:vc)
    {
        if (x&1)
            mn = min(mn,x);
    }
    cout << solve(mn);
    return 0;
}


Compiler output:
a.cc: In function 'll solve(ll)':
a.cc:17:14: error: no matching function for call to 'min(ll&, int)'
   17 |     lim = min(lim,n-1);
      |           ~~~^~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:17:14: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   17 |     lim = min(lim,n-1);
      |           ~~~^~~~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:17:14: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   17 |     lim = min(lim,n-1);
      |           ~~~^~~~~~~~~