#include<iostream>
using namespace std;
char s[4010];
long long n,a,b,c,ans;
int main()
{
    int i,j;
    cin>>n;
    for(i=1;i<=n;i++) 
    {
        cin>>s[i];
        if(s[i]=='R') a++;
        if(s[i]=='G') b++;
        if(s[i]=='B') c++;
    }
    ans=a*b*c;
    for(i=1;i<=n;i++)
     for(j=1;i-j>0&&i+j<=n;j++)
      if(s[i]!=s[i-j]&&s[i-j]!=s[i+j]&&s[i]!=s[i+j]) 
       ans--;
    cout<<ans;
    cin>>i;
    return 0;
}
        
    
