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

int main() {
  int n;string s;
  cin >> n >> s;
  int r = 0,g = 0,b = 0;
  for(int i = 0; i < n; i++){
    if(s[i] == 'R') r++;
    else if(s[i] == 'G') g++;
    else b++;
  }
  int all = r*g*b;
  int sub = 0;
  for(int i = 0; i < n; i++){
    for(int j = i+1; j < n; j++){
      if(s[i] == s[j]) continue;
      int k = 2 * j - i;
      if (k >= n || s[k] == s[i] || s[k] == s[j]) continue;
      sub++;
    }
  }
  int ans = all - sub;
  cout << ans << endl;
  return 0;
}