#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using P = pair<int, int>;
long mod = (long) 1e9 + 7;

int main(){
    
    int n;
    long cnt = 0, r = 0, g = 0, b = 0;
    cin >> n;
    
    string s;
    cin >> s;
    
    vector<int> v(n,0);
    rep(i,n){
        if(s[i] == 'R'){
            v[i] = 0;
            r++;
        } else if(s[i] == 'G'){
            v[i] = 1;
            g++;
        } else if(s[i] == 'B'){
            v[i] = 2;
            b++;
        }
    }
    
    for(int i = 1; i < n - 1; i++){
        int a = min(i, n - 1 - i);
        
        for(int j = 1; j <= a; j++){
            if(v[i] != v[i-j] && v[i] != v[i+j] && v[i-j] != v[i+j]) cnt++;
        }
    }
    
    long ans = r * g * b - cnt;
    
    cout << ans << "\n";
    
    return 0;
}

#include<iostream>
#include<string>
using namespace std;
int main()
{
    char s[5000];
    long long n,i,j,k,total=0,red[5000]={0},green[5000]={0},blue[5000]={0},r=0,g=0,b=0,x,y;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    for(i=1;i<=n;i++)
    {
        if(s[i]=='R')
        {
            r++;
            red[i]=red[i-1]+1;
            blue[i]=blue[i-1];
            green[i]=green[i-1];
        }
        else if(s[i]=='G')
        {
            g++;
            green[i]=green[i-1]+1;
            red[i]=red[i-1];
            blue[i]=blue[i-1];
        }
        else if(s[i]=='B')
        {
            b++;
            blue[i]=blue[i-1]+1;
            red[i]=red[i-1];
            green[i]=green[i-1];
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {          
            if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R'))
            {
                x=b-blue[j];
                y=(j-i)+j;
                if(s[y]=='B'&&x>0&&y<=n)
                {
                    x--;
                }
                if(x>0)
                {
                    total=total+x;
                }                
            }
            else if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R'))
            {
                x=g-green[j];
                y=(j-i)+j;
                if(s[y]=='G'&&x>0&&y<=n)
                {
                    x--;
                }
                if(x>0)
                {
                    total=total+x;  
                }              
            }
            else if((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B'))
            {
                x=r-red[j];
                y=(j-i)+j;
                if(s[y]=='R'&&x>0&&y<=n)
                {
                    x--;
                }
                if(x>0)
                {
                    total=total+x; 
                }               
            }
        }
    }
    cout<<total<<endl;
    return 0;
}