#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

int main()
{
    /*
    int n;
    cin>>n;
    while(n)
    {
        if(n%10==7)
        {
            cout<<"Yes"<<endl;
            return 0;
        }
        n=n/10;
    }
    cout<<"No"<<endl;
    */
    /*
    int n;
    cin>>n;
    ll total = 0;

    for(int i=1;i<=n;i++)
    {
        if(i%3!=0 && i%5!=0)
        {
            total+=i;
        }
    }
    cout<<total<<endl;
    */
    /*
    int k;
    cin>>k;
    ll total = 0;
    for(int i=1;i<=k;i++)
    {
        for(int j=1;j<=k;j++)
        {
            for(int l=1;l<=k;l++)
            {
                total+=gcd(gcd(i,j),l);
            }
        }
    }
    cout<<total<<endl;
    */

    int n;
    cin>>n;
    string s;
    cin>>s;
    pair <int,char> p[n];
    map <int,char> mp;
    for(int i=0;i<n;i++)
    {
        p[i].first=i+1;
        p[i].second=s[i];
        mp[s[i]]++;
    }
    int r = mp['R'];
    int g = mp['G'];
    int b = mp['B'];
    
    int count=0;
    count+=r*g*b;
    for(int j=0;j<n;j++)
    {
        for(int i=0;i<j;i++)
        {
            int k = j + (j-i);
            if (k < n) 
            {
                if (s[i] == s[j]) continue;
                if (s[i] == s[k]) continue;
                if (s[k] == s[j]) continue;
                count--;
            }
        }
    }
    cout<<count<<endl;

    return 0;
}