#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; (i) < (n); (i)++)
#define INF 5000000000000000
using namespace std;

struct Edge{
    int to;
    long weight;
    Edge(int t, long w) : to(t), weight(w) {}
};

long modpow(long a, long n, long mod) {
    long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

// a^{-1} mod を計算する
long modinv(long a, long mod) {
    return modpow(a, mod - 2, mod);
}

struct compare1 { 
    bool operator()(const pair<long, long>& value,  
                                const long& key) 
    { 
        return (value.first < key); 
    } 
    bool operator()(const long& key,  
                    const pair<long, long>& value) 
    { 
        return (key < value.first); 
    } 
};

struct UnionFind {
    vector<int> par;
    vector<int> rank;

    UnionFind(int n = 1){
        init(n);
    }

    void init(int n = 1){
        par.resize(n);
        rank.resize(n);
        REP(i, n) par[i] = i, rank[i] = 0; 
    }

    int root(int x){
        if(par[x] == x) return x;
        else return par[x] = root(par[x]);
    }

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y);
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        return true;
    }
};

template<class Abel> struct weightedUnionFind{
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    weightedUnionFind(int n = 1, Abel SUM_UNITY = 0){
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0){
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        REP(i, n) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY; 
    }

    int root(int x){
        if(par[x] == x) return x;
        else{
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x){
        root(x);
        return diff_weight[x];
    }

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y, Abel w){
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if(x == y) return false;
        if(rank[x] < rank[y]) swap(x, y), w = -w;
        if(rank[x] == rank[y]) rank[x]++;
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y){
        return weight(y) - weight(x);
    }
};

using Graph = vector<vector<int>>;
using P = pair<int, int>;

/*
void dijkstra(int s, int V, Graph &G, long* d){
    priority_queue<P, vector<P>, greater<P>> pque;
    fill(d, d + V, INF);
    d[s] = 0;
    pque.push(P(0, s));

    while(!pque.empty()){
        P p = pque.top(); pque.pop();
        int now = p.second;
        if(d[now] < p.first) continue;
        REP(i, G[now].size()){
            Edge e = G[now][i];
            if(d[e.to] > d[now] + e.weight){
                d[e.to] = d[now] + e.weight;
                pque.push(P(d[e.to], e.to));
            }
        }
    }
}
*/

int GCD(int a, int b){
    if(b == 0) return a; 
    if(a < b) return GCD(b, a);
    else return GCD(b, a%b);
}

int main()
{
    int N; cin >> N;
    string S; cin >> S;
    int rgb[3][4005];
    int rgbind[3];
    REP(i, 3) rgbind[i] = 0;
    REP(i, N){
        if(S[i] == 'R') rgb[0][rgbind[0]] = i, rgbind[0]++;
        if(S[i] == 'G') rgb[1][rgbind[1]] = i, rgbind[1]++;
        if(S[i] == 'B') rgb[2][rgbind[2]] = i, rgbind[2]++;
    }
    long ans = 0;
    /*
    REP(i, 3){
        REP(j, rgbind[i]) cout << rgb[i][j] << " ";
        cout << endl;
    }
    */
   REP(i, 3) REP(j, 3) REP(k, 3){
       if(i==j || i==k || j==k) continue;
       REP(l, rgbind[i]){
           int temp = (int)(upper_bound(rgb[j], rgb[j] + rgbind[j], rgb[i][l]) - rgb[j]);
           for(int m = temp; m<rgbind[j]; m++){
               int temp2 = (int)(upper_bound(rgb[k], rgb[k] + rgbind[k], rgb[j][m]) - rgb[k]);
               ans += (long)(rgbind[k] - temp2);
               //cout << i << j << k << " " << ans << endl;
               if(temp2 != rgbind[k])
                if(binary_search(rgb[k], rgb[k]+rgbind[k], 2*rgb[j][m]-rgb[i][l]) && 2*rgb[j][m]-rgb[i][l] >= rgb[k][temp2]) ans--;
           }
       }
   }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3624