#include <bits/stdc++.h>
#define r(i,n) for(int i = 0; i<n; i++)
typedef long long ll;
using namespace std;
const ll mod=1000000007;

int main() {
  ll n,count=0;
  cin >> n;
  string s;
  cin >> s;
  int a[3][n];
  r(i,n){
    a[0][i]=0;
    a[1][i]=0;
    a[2][i]=0;
  }
  r(i,n){
    if(s[i]=='R')a[0][i]++;
    if(s[i]=='G')a[1][i]++;
    if(s[i]=='B')a[2][i]++;
    
    if(i){
      a[0][i]+=a[0][i-1];
      a[1][i]+=a[1][i-1];
      a[2][i]+=a[2][i-1];
    }
  }
  for(int i=0; i<n;i++){
    for(int j=i+1;j<n;j++){
      if(s[i]==s[j])continue;
      else{
        if(s[i]=='R'&&s[j]=='G'){
          count+=a[2][n-1]-a[2][j];
          if(j*2-i<n&&s[j*2-i]=='B')count--;
        }
        if(s[i]=='G'&&s[j]=='R'){
          count+=a[2][n-1]-a[2][j];
          if(j*2-i<n&&s[j*2-i]=='B')count--;
        }
        if(s[i]=='R'&&s[j]=='B'){
          count+=a[1][n-1]-a[1][j];
          if(j*2-i<n&&s[j*2-i]=='G')count--;
        }
        if(s[i]=='B'&&s[j]=='R'){
          count+=a[1][n-1]-a[1][j];
          if(j*2-i<n&&s[j*2-i]=='G')count--;
        }
        if(s[i]=='G'&&s[j]=='B'){
          count+=a[0][n-1]-a[0][j];
          if(j*2-i<n&&s[j*2-i]=='R')count--;
        }
        if(s[i]=='B'&&s[j]=='G'){
          count+=a[0][n-1]-a[0][j];
          if(j*2-i<n&&s[j*2-i]=='R')count--;
        }
      }
    }
  }
  cout<<count<<endl;
}