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

signed main(){
  lint N; cin >> N;
  string s; cin >> s;
  lint cg = 0, cr  =0, cb = 0;
  for(lint i = 0; i < N; i++){
    if(s[i] == 'R') cr++;
    if(s[i] == 'G') cg++;
    if(s[i] == 'B') cb++;
  }
  lint ans = cg * cr * cb;
  for(lint i = 1; i <= N/2; i++){
    for(lint j = 0; j < N; j++){
      lint x = j, y = j + i, z = j + 2*i;
      if(y >= N || z >= N) continue;
      else if(s[x] != s[y] && s[y] != s[z] && s[x] != s[z]) ans--;
     }
  }
  cout << ans << endl;
}