Language: C++

/*   _/                _/                 _/_/_/   _/
  _/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
   _/     _/    _/   _/     _/    _/  _/_/_/     _/
  _/     _/    _/   _/     _/    _/  _/    _/   _/
   _/_/   _/_/       _/_/   _/_/      _/_/     _/ */
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
using ll=long long;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=1e18;
using P=pair<int,int>;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,ans=0,r[4005]={},g[4005]={},b[4005]={},cnt=0;
  string s;
  cin >> n >> s;
  for(int i=0; i<s.size(); i++) {
    if(s[i]=='R') {
      r[i+1]++;
    }
    else if(s[i]=='G') {
      g[i+1]++;
    }
    else {
      b[i+1]++;
    }
  }
  for(int i=1; i<=s.size(); i++) {
    r[i]+=r[i-1];
    g[i]+=g[i-1];
    b[i]+=b[i-1];
  }
  for(int i=0; i<s.size(); i++) {
    if(s[i]=='R') {
      cnt=0;
      for(int j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='G'&&s[i+j]=='B') {
          cnt++;
        }
      }
      ans+=g[i]*(b[s.size()]-b[i])-cnt;
      cnt=0;
      for(int j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='B'&&s[i+j]=='G') {
          cnt++;
        }
      }
      ans+=b[i]*(g[s.size()]-g[i])-cnt;
    }
    else if(s[i]=='G') {
      cnt=0;
      for(int j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='R'&&s[i+j]=='B') {
          cnt++;
        }
      }
      ans+=r[i]*(b[s.size()]-b[i])-cnt;
      cnt=0;
      for(int j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='B'&&s[i+j]=='R') {
          cnt++;
        }
      }
      ans+=b[i]*(r[s.size()]-r[i])-cnt;
    }
    else {
      cnt=0;
      for(int j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='R'&&s[i+j]=='G') {
          cnt++;
        }
      }
      ans+=r[i]*(g[s.size()]-g[i])-cnt;
      cnt=0;
      for(int j=1; j<=min(n-(i+1),i); j++) {
        if(s[i-j]=='G'&&s[i+j]=='R') {
          cnt++;
        }
      }
      ans+=g[i]*(r[s.size()]-r[i])-cnt;
    }
  }
  cout << ans << endl;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:47:26: error: no matching function for call to 'min(ll, int&)'
   47 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
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:6:
/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:47:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   47 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
/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,
                 from a.cc:7:
/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:47:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   47 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
a.cc:54:26: error: no matching function for call to 'min(ll, int&)'
   54 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
/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:54:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   54 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
/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
/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:54:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   54 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
a.cc:63:26: error: no matching function for call to 'min(ll, int&)'
   63 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
/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:63:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   63 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
/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
/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:63:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   63 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
a.cc:70:26: error: no matching function for call to 'min(ll, int&)'
   70 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
/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:70:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   70 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
/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
/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:70:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   70 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
a.cc:79:26: error: no matching function for call to 'min(ll, int&)'
   79 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
/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:79:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   79 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
/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
/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:79:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   79 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
a.cc:86:26: error: no matching function for call to 'min(ll, int&)'
   86 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
/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:86:26: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   86 |       for(int j=1; j<=min(n-(i+1),i); j++) {
      |                       ~~~^~~~~~~~~~~
/usr/include/c