#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;
    vector<int> r;
    vector<int> g;
    vector<int> b;
    for(int i = 0; i < n; i++) {
        if(s[i]=='R')      r.emplace_back(i);
        else if(s[i]=='G') g.emplace_back(i);
        else               b.emplace_back(i);
    }
    int rs=r.size();
    int gs=g.size();
    int bs=b.size();
    int 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;
}