#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
    int N;
  cin >> N;
  string S;
  cin >> S;
     int r = 0;
     int g = 0;
     int b = 0;
    for(int i = 0; i < S.size(); i++) {
        if(S[i] == 'R') r += 1;
        else if(S[i] == 'G') g += 1;
        else if(S[i] == 'B') b += 1; 
    }

    ll ans = r * b * g;
    int s = 0;
    for(int i = 0; i < N; i++) {
        for(int j = i + 1; j < N; j++) {
            
            if(S[i] == S[j]) continue;
            int k = 2 * j - i;
            if(k >= N || S[k] == S[j] || S[i] == S[k]) s++;
        }
    }

    cout << ans - s;

    return 0;

}