#include <bits/stdc++.h>

using namespace std;
vector <int>r;
vector <int>g;
vector <int>b;
vector <int>::iterator  it;
string s;
int main(){

    int n, i, j, l;
    cin>>n>>s;
    for(i=0;i<s.size();i++)
    {
        if(s[i] =='R')
        {
            r.push_back(i);
            continue;
        }
        if(s[i] =='B')
        {
            b.push_back(i);
            continue;
        }
        if(s[i] =='G')
        {
            g.push_back(i);
            continue;
        }
    }
    long long sum =0;
    for(i=0; i<s.size()-2;i++)
    {
       for(j=i+1; j< s.size()-1; j++)
       {
           if(s[i]== s[j])
               continue;
           if(s[i] == 'R' || s[j] == 'R')
           {
               if(s[i] == 'B' || s[j] == 'B')
               {
                   it = upper_bound(g.begin(), g.end(), j);
                   int val = g.size() - (it - g.begin());
                   int x = j+(j - i);
                   bool ok  = binary_search(g.begin(), g.end(), x);
                   if(ok == true)
                       val--;
                   sum = sum + val;
                   continue;

               }
               if(s[i] == 'G' || s[j] == 'G'){
                   it = upper_bound(b.begin(), b.end(), j);
                   int val = b.size() - (it - b.begin());
                   int x = j+(j - i);
                   bool ok  = binary_search(b.begin(), b.end(), x);
                   if(ok == true)
                       val--;
                   sum = sum + val;
                   continue;
               }
           }
           if(s[i] == 'G' || s[j] == 'G')
           {
               if(s[i] == 'B' || s[j] == 'B')
               {
                   it = upper_bound(r.begin(), r.end(), j);
                   int val = r.size() - (it - r.begin());
                   int x = j+(j - i);
                   bool ok  = binary_search(r.begin(), r.end(), x);
                   if(ok == true)
                       val--;
                   sum = sum + val;
                   continue;
               }
               if(s[i] == 'R' || s[j] == 'R'){
                   it = upper_bound(b.begin(), b.end(), j);
                   int val = b.size() - (it - b.begin());
                   int x = j+(j - i);
                   bool ok  = binary_search(b.begin(), b.end(), x);
                   if(ok == true)
                       val--;
                   sum = sum + val;
                   continue;
               }
           }
           if(s[i] == 'B' || s[j] == 'B')
           {
               if(s[i] == 'R' || s[j] == 'R')
               {
                   it = upper_bound(g.begin(), g.end(), j);
                   int val = g.size() - (it - g.begin());
                   int x = j+(j - i);
                   bool ok  = binary_search(g.begin(), g.end(), x);
                   if(ok == true)
                       val--;
                   sum = sum + val;
                   continue;
               }
               if(s[i] == 'G' || s[j] == 'G'){
                   it = upper_bound(r.begin(), r.end(), j);
                   int val = r.size() - (it - r.begin());
                   int x = j+(j - i);
                   bool ok  = binary_search(r.begin(), r.end(), x);
                   if(ok == true)
                       val--;
                   sum = sum + val;
                   continue;
               }
           }

       }
    }
    cout<<sum<<"\n";

    return 0;
}


Measured memory_bytes: 3656