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

string s;
bool check(int a,int b,int c)
{
   char ch[3];
   ch[0] = s[a] ;
   ch[1] = s[b] ;
   ch[2] = s[c] ;
   sort(ch,ch+3);
   if(ch[0] == 'B' && ch[1] == 'G' && ch[2] == 'R')
      return true ;
   return false;
}

int main()
{
   int n;

   cin >> n >> s;
   int r = 0, g = 0, b = 0;
   for(int i =0; i < n; i++)
   {
      if(s[i] == 'R')
         r++;
      if(s[i] == 'G')
         g++;
      if(s[i] == 'B')
         b++;
   }
   int res = 0;
   for(int i = 0 ; i < n; i++)
   {
      for(int j = i+1; j < n; j++)
      {
         int k = (i+j)/2;
         if(k -i == j - k && check(i,j,k))
            res++;

      }
   }
   cout << b*r*g - res;
   return 0;
}
