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

int main() {
  int N;
  string S;
  
  cin >> N >> S;

  // Count OKs
  int Rs = 0;
  int Gs = 0;
  int Bs = 0;
  for (int i = 0; i < N; i++) {
    if(S[i]=='R') Rs++;
    if(S[i]=='G') Gs++;
    if(S[i]=='B') Bs++;
  }

  // Count NGs
  int ngCount = 0;
  for (int i = 0; i < N-1; i++) {
    char first = S[i];
    for (int j = i+1; j < N; j++) {
      char second = S[j];
      int distance = j - i;
      if (first != second && j+distance < N){
        char third = S[j+distance];
        if(third != first && third != second){
          ngCount++;
        }
      }
    }
  }
    
  long answer = Rs*Gs*Bs - ngCount;
  
    cout << answer << endl;
    return 0;
}
