#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  cout<<fixed;
  int n;
  cin>>n;
  string s;
  cin>>s;
  ll sr=0,sg=0,sb=0;
  rep(i,n) {
    if(s[i]=='R')sr++;
    if(s[i]=='G')sg++;
    if(s[i]=='B')sb++;
  }
  ll x=0;
  repeat(j,1,n-1) {
    repeat(d,1,n) {
      int i=j-d;
      int k=j+d;
      if(i<0||n<=k)
	break;
      if(s[i]!=s[j]&&s[i]!=s[k]&&s[j]!=s[k]) {
	x++;
      }
    }
  }
  cout << sr*sg*sb-x << endl;
  return 0;
}
