#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int sumr[n]={},sumg[n]={},sumb[n]={};
    if(s[0]=='R'){
        sumr[0]=1;
        sumg[0]=0;
        sumb[0]=0;
    }
    if(s[0]=='G'){
        sumg[0]=1;
        sumr[0]=0;
        sumb[0]=0;
    }
    if(s[0]=='R'){
        sumb[0]=1;
        sumg[0]=0;
        sumr[0]=0;
    }

    //cout << sumr[0] << " " << sumb[0] << " " << sumg[0] << endl; 
    for(int i=1; i<n; i++){
        if(s[i]=='R'){
            sumr[i]=sumr[i-1]+1;
            sumb[i]=sumb[i-1];
            sumg[i]=sumg[i-1];
        }
        if(s[i]=='G'){
            sumg[i]=sumg[i-1]+1;
            sumb[i]=sumb[i-1];
            sumr[i]=sumr[i-1];
        }
        if(s[i]=='B'){
            sumb[i]=sumb[i-1]+1;
            sumr[i]=sumr[i-1];
            sumg[i]=sumg[i-1];
        }
    }
   
    cout << endl;
    int cnt=0;
    for(int i=0; i<n-1; i++){
        for(int j=i+1; j<n; j++){
            if(s[i]=='R'&&s[j]=='G'){
                cnt+=sumb[n-1]-sumb[j];
                if(2*j-i<n&&s[2*j-i]=='B')cnt--;
            }if(s[i]=='R'&&s[j]=='B'){
                cnt+=sumg[n-1]-sumg[j];
                if(2*j-i<n&&s[2*j-i]=='G')cnt--;
            }if(s[i]=='B'&&s[j]=='G'){
                cnt+=sumr[n-1]-sumr[j];
                if(2*j-i<n&&s[2*j-i]=='R')cnt--;
            }if(s[i]=='G'&&s[j]=='R'){
                cnt+=sumb[n-1]-sumb[j];
                if(2*j-i<n&&s[2*j-i]=='B')cnt--;
            }if(s[i]=='G'&&s[j]=='B'){
                cnt+=sumr[n-1]-sumr[j];
                if(2*j-i<n&&s[2*j-i]=='R')cnt--;
            }if(s[i]=='B'&&s[j]=='R'){
                cnt+=sumg[n-1]-sumg[j];
                if(2*j-i<n&&s[2*j-i]=='G')cnt--;
            }
        }
    }
    cout << cnt << endl;
}