#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
#include<cstdlib>
using namespace std;
 
#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592
 
const double EPS = 1e-10;
 
using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;



int main(){
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int>> sum(n,vector<int>(3));
    map<char,int> mp;
    mp['R'] = 0;
    mp['G'] = 1;
    mp['B'] = 2;
    sum[n-1][mp[s[n-1]]]++;
    for(int i = n-2; i >= 0; i--){
        rep(j,3) sum[i][j] = sum[i+1][j];
        sum[i][mp[s[i]]] = sum[i+1][mp[s[i]]]+1;
    }
    ll ans = 0;
    rep(i,n-2)repr(j,i+1,n-1){
        if(s[i] == s[j]) continue;
        int k = 3-mp[s[i]]-mp[s[j]];
        ans += sum[j+1][k];
        if(2*j-i < n && mp[s[j+j-i]] == k) ans--;
    }
    cout << ans << endl;
       
}
