#include <bits/stdc++.h>
#include <math.h>
 
#define rep(i, n) for(int i = 0; (int)(i) < n; i++)
 
using namespace std;
 
int main() {
  int N;
  string S;
  cin >> N >> S;
  int r = 0;
  int g = 0;
  int b = 0;
  
  for(char c : S){
    if(c == 'R') r++;
    else if(c == 'G') g++;
    else b++;
  }
  long long all = r * g * b;
  int sub = 0;
  
  for(int i = 0; i < N; i++){
    for(int j = i + 1; j < N; j++){
      if(S[i] == S[j]) continue;
      int k = j * 2 - i;
      if(k >= N || S[k] == S[i] || S[k] == S[j]) continue;
      sub++;
    }
  }
  cout << all - sub << endl;
}