#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  int n;
  std::cin >> n;
  std::string s;
  std::cin >> s;

  int r = 0, g = 0, b = 0;
  rep(i,n) {
    if(s[i] == 'R')
      r++;
    else if(s[i] == 'G')
      g++;
    else
      b++;
  }

  ll to = r*g*b;
  rep(i,n){
    for(int j = i+1; j < n; j++){
      int k = 2*j - i;
      if(k >= n) break;
      if(s[i] != s[j] && s[j] != s[k] && s[k] != s[i])
      to--;
    }
  }

  std::cout << to << '\n';
  return 0;
}
