#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)

int main() {
    int n; cin >> n;
    string s; cin >> s;
    vector<vector<int>> a(n,vector<int>(3,0));
    if(s[0] == 'R') a[0][0]++;
    else if(s[0] == 'G') a[0][1]++;
    else a[0][2]++;
    for(int i = 1; i < n; i++){
        a[i][0] = a[i-1][0];
        a[i][1] = a[i-1][1];
        a[i][2] = a[i-1][2];
        char si = s[i];
        if(si == 'R') a[i][0]++;
        else if(si == 'G') a[i][1]++;
        else a[i][2]++;
    }

    int64_t ans = 0;
    for(int i = 1; i < n; i++){
        int si;
        if(s[i] == 'R') si = 0;
        else if(s[i] == 'G') si = 1;
        else si = 2;
        for(int j = i+1; j < n; j++){
            int sj;
            if (s[j] == 'R') sj = 0;
            else if (s[j] == 'G') sj = 1;
            else sj = 2;
            if(si == sj) continue;
            int clr = 3-si-sj;
            ans += a[i-1][clr];
            int ng = 2*i-j;
            if(ng >= 0){
                if(clr == 0 && s[ng] == 'R'){
                    ans--;
                }
                if (clr == 1 && s[ng] == 'G'){
                    ans--;
                }
                if (clr == 2 && s[ng] == 'B'){
                    ans--;
                }
            }
        }
    }
    
    cout << ans << endl;
}
