#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define inv(n, a) for(int i = 0; i < n; i++) cin >> a[i]
#define MOD 1000000007
#define INF 1e7
#define LINF 1e15
typedef long long ll;
typedef long double ld;
using Graph = vector<vector<int>>;
// 'a' = 97 'z' = 122 => 'a' = 0 'z' = 25

int main() {
    int n; string s;
    cin >> n >> s;
    struct st{
        ll r;
        ll g;
        ll b;
    };
    vector<st> sv(n);
    sv[0].r = 0; sv[0].g = 0; sv[0].b = 0;
    for(int i = 1; i < n; i++){
        sv[i].r = sv[i-1].r; sv[i].g = sv[i-1].g; sv[i].b = sv[i-1].b;
        if(s[i] == 'R') sv[i].r++;
        if(s[i] == 'G') sv[i].g++;
        if(s[i] == 'B') sv[i].b++;
    }
    ll ans = 0;
    for(int i = 0; i < n-3; i++){
        for(int j = i+1; j < n-1; j++){
            if(s[i] == s[j]) continue;
            if(s[i] != 'R' && s[j] != 'R'){ //s[k]は'R'
                ans += sv[n-1].r - sv[j].r;
                if(s[j + (j-i)] == 'R') ans--;
            }
            if(s[i] != 'G' && s[j] != 'G'){
                ans += sv[n-1].g - sv[j].g;
                if(s[j + (j-i)] == 'G') ans--;
            }
            if(s[i] != 'B' && s[j] != 'B'){
                ans += sv[n-1].b - sv[j].b;
                if(s[j + (j-i)] == 'B') ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


