#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  string s;
  ll n;
  cin >> n >> s;
  
  ll r=0, g=0, b=0;
  rep(i, 0, n) {
    if(s[i] == 'R') r++;
    if(s[i] == 'G') g++;
    if(s[i] == 'B') b++;
  }
  
  ll ans = r*g*b;
  rep(i, 1, n-1) {
    ll L = min(n-1-i+1, (ll)(i-0+1));
    rep(j, 1, L) {
      if(s[i-j] != s[i] and s[i] != s[i+j] and s[i+j] != s[i-j]) ans--;
    }
  }
  cout << ans << "\n";
}