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

typedef long long ll;

ll check(vector<int> a, vector<int> b, vector<int> c){
    ll ans = 0;
    for(int i = 0; i < a.size(); i++){
        for(int j = 0; j < b.size(); j++){
            if(b[j] < a[i]){
                continue;
            }
            int target = b[j] + (b[j] - a[i]);
            auto itr = find(c.begin(), c.end(), target);
            if(itr != c.end()){
                ans++;
            }
        }
    }
    
    return ans;
}


// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    cin >> N;
    string S ;
    cin >> S;

    vector<int> a;
    vector<int> b;
    vector<int> c;
    for(int i = 0; i < N; i++){
        if(S[i] == 'R' ) a.push_back(i+1);
        if(S[i] == 'G' ) b.push_back(i+1);
        if(S[i] == 'B' ) c.push_back(i+1);
    }
    ll ans = 0;
    ans = a.size() * b.size() * c.size();
    ans -= check(a,b,c);
    ans -= check(a,c,b);
    ans -= check(b,c,a);
    ans -= check(b,a,c);
    ans -= check(c,a,b);
    ans -= check(c,b,a);
    cout << ans << endl;
}
