#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <queue>
#include <climits>
#include <utility>
typedef long long ll;
using namespace std;

int main(void){
  int n, i, j;
  string s;

  cin >> n >> s;

  int r, g, b;
  r = g = b = 0;

  for(i=0;i<n;i++){
    if(s[i]=='R'){
      ++r;
    }
    else if(s[i]=='G'){
      ++g;
    }
    else if(s[i]=='B'){
      ++b;
    }
  }

  int cnt = 0;

  for(i=1;i<n/2;i++){
    j = 0;
    while(2*i+j<n){
      if(s[j]!=s[j+i]&&s[j]!=s[j+2*i]&&s[j+i]!=s[j+2*i]){
        ++cnt;
      }
      j++;
    }
  }

  cout << r * g * b - cnt << endl;

  return 0;
}
