#include <bits/stdc++.h>
#include <math.h>
using namespace std;


int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  long long r = 0;
  long long g = 0;
  long long b = 0;
  for(int i = 0; i < n; i++){
      if(s[i] == 'R'){r++;}
      else if(s[i] == 'G'){g++;}
      else if(s[i] == 'B'){b++;} 
  }
    long long cnt = 0;
    if(r == 0 || g == 0 || b == 0){
        cout << 0 << endl;
    }
    else{
        cnt = r * g * b;
        for(int i = 1; i <= (n - 1) / 2; i++){
            for(int j = 0; j < n - 2 * i; j++){
                if(s[j] != s[j + i] && s[j] != s[j + 2*i] && s[j + i] != s[j + 2*i]){
                    cnt--;
                }
            }
        }
        if(cnt < 0){cnt = 0;}
        cout << cnt << endl;
    }
}
