// Aggressive Play
 
#include<bits/stdc++.h>
#define ll long long
 
using namespace std;
const int N = 4e3 + 5;
const int k = 3;
int a[N][k];
int main()
{
    ios_base ::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int n;
    cin >> n;
    string s;
    cin >> s;
    s = "@" + s;
    map<char, int> mp;
    mp['R'] = 0;
    mp['G'] = 1;
    mp['B'] = 2;
    for(int i = 1; i <= n; i++){
        for(int j = 0; j < k; j++){
            a[i][j] = a[i - 1][j];
        }
        a[i][mp[s[i]]]++;
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = i + 2; j <= n; j++){
            if(s[i] == s[j]) continue;
            vector<int> h(k, 0);
            for(int kk = 0; kk < k; kk++){
                h[kk] = a[j - 1][kk] - a[i][kk];
            }
            int diff = j - i;
            if(diff % 2 == 0){
                int mid = (i + j) / 2;
                h[mp[s[mid]]]--;
            }
            h[mp[s[i]]] = 0;
            h[mp[s[j]]] = 0;
            for(int kk = 0; kk < k; kk++)
                ans += h[kk];
        }
    }
    cout << ans;
return 0;
}