#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i < (int)(n); i++)
#define Sort(a) sort(a.begin(), a.end())
typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return true;} return false;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return true;} return false;}

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int r = 0, g = 0, b = 0;
    rep(i, n){
        if(s.at(i) == 'R') r++;
        if(s.at(i) == 'G') g++;
        if(s.at(i) == 'B') b++;
    }
    ll sum = r*g*b;
    r = 0; g = 0; b = 0;
    REP(i, n){
        rep(j, i){
            for(int k = j; k < n; k+=i){
                if(s.at(k) == 'R') r = 3;
                if(s.at(k) == 'G') g = 3;
                if(s.at(k) == 'B') b = 3;
                if(r > 0 && g > 0 && b > 0) sum--;
                r--; g--; b--;
                //cout << k << " ";
                //cout << r <<" "<< g <<" "<<b << endl;
            }
            //cout << endl;
            r = 0; g = 0; b = 0;
        }
    }
    cout << sum << endl;
    return 0;
}