#include<iostream>
#include<string>
#include<set>
using namespace std;

int main() {
  int N; string S; cin >> N >> S;
  int r,g,b,rg,gb,br,rgb;
  r=g=b=rg=gb=br=rgb=0;
  for (int i = 0; i < N; i++) {
    if (S[i] == 'R') { r++; rg += g; br += b; rgb += gb; }
    else if (S[i] == 'G') { g++; rg += r; gb += b; rgb += br; }
    else if (S[i] == 'B') { b++; gb += g; br += r; rgb += rg; }
  }
  for (int i = 0; i < N-2; i++) {
    for (int j = i+1; j < N-1; j++) {
      int k = 2 * j - i;
      if (k >= N) break;
      set<char> s;
      s.insert(S[i]);
      s.insert(S[j]);
      s.insert(S[k]);
      if (s.size() == 3) rgb--;
    }
  }
  cout << rgb << endl;
}
