#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
template<class T> inline bool chmin(T& a, T b){if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a=b;return true;}return false;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    ll ans=0;
    string x; cin>>x;
    string s="i";
    s+=x;
    ll Bcnt=0;
    rep1(i,N){
        if(s[i]=='B') Bcnt++;
    }
    rep1(R,N)rep1(G,N){
        if(s[R]=='R' && s[G]=='G'){ //B探す
            ll ans1,ans2,ans3,tmp=Bcnt;
            if(abs(R-G)%2==0){
                ans1=(R+G)/2;
                if(s[ans1]=='B') tmp--;
            }
            ans2=2*R-G;
            if(1<=ans2 && ans2<=N && s[ans2]=='B') tmp--;
            ans3=2*G-R;
            if(1<=ans3 && ans3<=N && s[ans3]=='B') tmp--;
            
            ans+=tmp;
        }
    }
    cout<<ans<<endl;
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000000 //10^12:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second //pairの二つ目の要素


int main(){
    int N;
    string S;
    cin>>N>>S;
    vector<int> v(3);
    rep(i,N) v[S[i]%3]++;
    ll ans=(ll)v[0]*v[1]*v[2];
    ll sub=0;
    rep(i,N){
        for(int j=i+1;j<N;j++){
            if(S[i]==S[j]) continue;
            int k=2*j-i;
            if(k>=N) continue;
            if(S[i]==S[k] || S[j]==S[k]) continue;
            sub++;
        }
    }
    ans-=sub;
    cout<<ans<<endl;
    return 0;
}
