#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<char>cvec;
typedef pair<ll, ll> LP;
typedef tuple<ll, ll, ll> LT;
typedef pair<int, int> P;
typedef tuple<int, int, int> T;
int main()	{
  int n;string s;
  cin>>n>>s;
  ll a=0,b=0,c=0;
  ll sum1,sum2=0;
  rep(i,n){
    if(s[i]=='R')
      a++;
    else if(s[i]=='G')
      b++;
    else
      c++;
  }
  sum1=a*b*c;
  rep(i,n){
    for(j=i+1;j<n;j++){
      if(s[i]==s[j]) continue;
      int k=2*j-i;
      if(s[i]==s[k]||s[j]==s[k]||k>=n)
        sum2++;
    }
  }
  cout<<sum1-sum2<<endl;
}