#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>
#include <functional>
#include <iomanip>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ;
#endif

#define equals(a,b) (fabs((a)-(b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back

//#define int long long

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

template <typename T>
void print_array(const T &ary, int size){
    REP(i,size){
        cout << ary[i] << " ";
    }
    cout << endl;
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
const double EPS = (1e-10);

signed main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(12);
    int N; cin >> N;
    string S; cin >> S;
    set<int> s[3];
    VVI acc(3,VI(N+1));
    REP(i,N){
        if(S[i] == 'R') {
            acc[0][i+1] = acc[0][i] + 1;
            acc[1][i+1] = acc[1][i] + 0;
            acc[2][i+1] = acc[2][i] + 0;
        }
        if(S[i] == 'G') {
            acc[1][i+1] = acc[1][i] + 1;
            acc[0][i+1] = acc[0][i] + 0;
            acc[2][i+1] = acc[2][i] + 0;
        }
        if(S[i] == 'B') {
            acc[2][i+1] = acc[2][i] + 1;
            acc[0][i+1] = acc[0][i] + 0;
            acc[1][i+1] = acc[1][i] + 0;
        }
    }
    LL ans = 0;
    FOR(i,1,N-1){
        if(S[i] == 'G'){
            LL r = acc[0][i];
            LL b = acc[2][N] - acc[2][i];
            LL cr = acc[0][N]-acc[0][i];
            LL cb = acc[2][i];
            ans += r*b;
            ans += cr*cb;
            //dump(r)
            //dump(b)
            //dump(cr)
            //dump(cb)

            for(int j = i-1; j >= 0; j--){
                if(S[j] == 'R' && S[i+(i-1-j+1)] == 'B'){
                    ans--;
                }
                if(S[j] == 'B' && S[i+(i-1-j+1)] == 'R'){
                    ans--;
                }

            }
        }
        if(S[i] == 'R'){
            LL g = acc[1][i];
            LL b = acc[2][N] - acc[2][i];
            LL cg = acc[1][N]-acc[1][i];
            LL cb = acc[2][i];
            ans += g*b;
            ans += cg*cb;

            for(int j = i-1; j >= 0; j--){
                if(S[j] == 'G' && S[i+(i-1-j+1)] == 'B'){
                    ans--;
                }
                if(S[j] == 'B' && S[i+(i-1-j+1)] == 'G'){
                    ans--;
                }

            }
        }
        if(S[i] == 'B'){
            LL r = acc[0][i];
            LL g = acc[1][N] - acc[1][i];
            LL cr = acc[0][N]-acc[0][i];
            LL cg = acc[1][i];
            ans += r*g;
            ans += cr*cg;

            for(int j = i-1; j >= 0; j--){
                if(S[j] == 'R' && S[i+(i-1-j+1)] == 'G'){
                    ans--;
                }
                if(S[j] == 'G' && S[i+(i-1-j+1)] == 'R'){
                    ans--;
                }

            }
        }
        //dump(ans)



    }
    cout << ans << endl;


}


Measured memory_bytes: 3684