#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <cstdlib>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <stack>
#include <functional>
#include <sstream>
#define rep(i,j,n) for(i=j;i<(n);i++)
#define rrep(i,j,n) for(i=j;i>(n);i--)
typedef long long int lli;
#define N 1000000007
#define M 998244353

using namespace std;

int main(){
    lli n,sum=0;
    string s;
    lli i,j,k;
    vector<lli> R,G,B;
    cin>>n>>s;
    rep(i,0,n){
        switch(s[i]){
            case 'R':R.push_back(i);break;
            case 'G':G.push_back(i);break;
            case 'B':B.push_back(i);break;
        }
    }
    rep(i,0,R.size()){
        rep(j,0,G.size()){
                rep(k,0,B.size()){
                        if((abs(B[k]-G[j])==abs(G[j]-R[i]))||(abs(B[k]-G[j])==abs(B[k]-R[i]))||(abs(B[k]-R[i])==abs(G[j]-R[i]))){
                            sum++;
                        }
                }
        }
    }
    cout<<R.size()*G.size()*B.size()-sum<<endl;
}
