#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
    int N;
    string S;
    cin >> N >> S;
    vector<int>a(N);
    rep(i,N) {
        if(S[i]=='R') a[i] = 0;
        if(S[i]=='G') a[i] = 1;
        if(S[i]=='B') a[i] = 2;
    }
    vector<ll>cnt(3);
    rep(i,N) cnt[a[i]]++;
    ll ans = 1;
    rep(i,3) ans *= cnt[i];
    rep(j,N) {
        rep(i,j) {
            int k = j+j-i;
            if(k<N) {
                if(a[i] == a[j]) continue;
                if(a[j] == a[k]) continue;
                if(a[i] == a[k]) continue;
                ans--;
            }
        }
    }
    cout << ans << endl;
}