        #include <bits/stdc++.h>
        using namespace std;
        #define int long long int
        #define pb push_back
        #define mk make_pair
        #define ft first
        #define sc second
        #define ppb pop_back
        #define sz size
        #define forn(i,a,n) for(i=a;i<n;i++)
        #define M 998244353 
        #define inf 2e18
 
        bool check(int n,int k){
            while(n%k==0){
                n=n/k;
            }
            return n%k==1;
        }
        
        signed main() {

        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        
        int n;
        cin>>n;
        string s;
        cin>>s;
        int r=0,b=0,g=0;
        for(int i=0;i<s.length();i++){
            if(s[i]=='R')r++;
            if(s[i]=='B')b++;
            if(s[i]=='G')g++;
        }

        int ans=r*b*g;
        int k=0;
        for(int i=0;i<n;i++){
            for(int j=i+1;j<n;j++){

                if(s[i]!=s[j] && 2*j-i<n){
                    if(s[i]!=s[2*j-i]&&s[j]!=s[2*j-i])k++;
                }
            }
        }
        cout<<ans-k;


        return 0;
    }