#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX Euclidean */           ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int main(){
   int n;
   cin >> n;
   string s;
   cin >> s;
   ll zenntai = 1;
   for(int i=0;i<3;i++){
      ll che = 0;
      for(int j=0;j<n;j++){
         if(i==0){
            if(s.at(j)=='R')che++;
         }
         else if(i==1){ 
            if(s.at(j)=='B')che++;
         }
         else {
            if(s.at(j)=='G')che++;
         }
      }
      zenntai*=che;
   }
   ll hosyu = 0;
   for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
         int k= j+j-i;
         if(k>=n)continue;
         string che = "";
         che+=s.at(i);
         che+=s.at(j);
         che+=s.at(k);
         sort(che.begin(),che.end());
         if(che=="BGR")hosyu++;
      }
   }
   ll ans = zenntai - hosyu;
   cout << ans << endl;
}
    

