#include<bits/stdc++.h>
using namespace std;
int main()
{
  int64_t N,i=0,j,k,r=0,g=0,b=0,count=0;
  string S;
  cin>>N>>S;
  for(char c:S){if(c=='R')r++;else if(c=='G')g++;else b++;}
  count=r*g*b;
  while(i<N)
  {
    j=1;k=2*j;
    while(i+k<N)
    {
      if((S.at(i)^S.at(i+j)^S.at(i+k))==87)count--;
      j++;k=2*j;
    }
    i++;
  }
  return cout<<count<<endl,0;
}