#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll n;
    cin>>n;
    string ss;
    cin>>ss;
    set<ll>s;
    vector<ll>red,green,blue;
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        if(ss[i]=='R')
        {
            red.push_back(i);
        }

        else if(ss[i]=='G')
        {
            green.push_back(i);
        }
        else
        {
            blue.push_back(i);
        }
    }

    for(int i=0;i<red.size();i++)
    {
        for(int j=0;j<green.size();j++)
        {

            for(int k=0;k<blue.size();k++)
            {
                if(red[i]<green[j] && green[j]<blue[k] && green[j]-red[i] !=blue[k]-green[j])
                {
                    sum++;
                }
                else if(red[i]>green[j] && green[j]>blue[k] && green[j]-red[i] !=blue[k]-green[j])
                {
                    sum++;
                }
                else if(green[j]<red[i] && red[i]<blue[k] && green[j]-red[i] !=red[i]-blue[k])
                {
                    sum++;
                }
                else if(green[j]<blue[k] && blue[k]<red[i] && green[j]-blue[k]!=blue[k]-red[i]) {sum++;}
                  else if(green[j]>red[i] && red[i]>blue[k] && green[j]-red[i] !=red[i]-blue[k])
                {
                    sum++;
                }
                else if(green[j]>blue[k] && blue[k]>red[i] && green[j]-blue[k]!=blue[k]-red[i]) {sum++;}
        }
    }

    }

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