#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;
typedef long long LL;

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  int cR = 0, cG = 0, cB = 0;
  REP(i, N) {
    if(S[i] == 'R') cR++;
    if(S[i] == 'G') cG++;
    if(S[i] == 'B') cB++;
  }
  int ret = cR * cG * cB;
  for(int i=1; i<N-1; ++i) {
    for(int j=i-1; j>=0 && i*2-j < N; --j) {
      if(S[i] != S[j]  && S[i] != S[i*2-j] && S[j] != S[i*2-j]) ret--;
    }
  }
  cout << ret << endl;
}