#include <bits/stdc++.h>

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    string s;
    cin >> n >> s;
    int rs=0;
    int gs=0;
    int bs=0;
    for(int i = 0; i < n; i++) {
        if(s[i]=='R')      rs++;
        else if(s[i]=='G') gs++;
        else               bs++;
    }
    ll ans=rs*bs*gs;
//    cout << rs << " " << bs << " " << gs << "\n";
    for(int w = 1; 2*w < n; w++) {
        for(int m = w; m+w <n ; m++) {
//        cout << m << " " << w << "\n";
            if(s[m]!=s[m-w] && s[m]!=s[m+w] && s[m-w]!=s[m+w]) ans--;
        }
    }
    cout << ans << "\n";
    return 0;
}