#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<iomanip>
#include<map>
#include<utility>
#include<string>
#include<unordered_map>
#include<queue>

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
#define max_3(a, b, c) max(a, max(b, c))
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a, int b){return b ? gcd(b, a%b) : a;}


int main(){
   int n;
   string s;
   cin >> n >> s;
   vector<int> a(n);
   for(int i = 0; i < n; i++){
      if(s[i] == 'R') a[i] = 0;
      if(s[i] == 'G') a[i] = 1;
      if(s[i] == 'B') a[i] = 2;
   }
   vector<ll> cnt(3);
   for(int i = 0; i < n; i++) cnt[a[i]]++;
   ll ans = 1;
   for(int i = 0; i < 3; i++) ans *= cnt[i]; //(r,g,b)のパターン数

   for(int i = 0; i < n; i++){
      for(int j = i+1; j < n; j++){
         int k = j+(j-i);
         if(k < n){
            if(a[i] == a[j]) continue; //1つ目の条件は満たしているので考えない
            if(a[i] == a[k]) continue;
            if(a[j] == a[k]) continue;
            ans--;
         }
      }
   }
   cout << ans << endl;
   return 0;
}
 