#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define MAXN 200 + 5
const long long INF = 1LL << 60;
const int inf = 1 << 30;

void printVec(std::vector<ll> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}
 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


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

  ll ans = 0;
  unordered_map<char, int> mp;
  vector<vector<int>> vv(3, vector<int> (n+1));
  vv[0][0] = 0;
  vv[1][0] = 0;
  vv[2][0] = 0;
  rep(i, 0, n){
    mp[s[i]]++;
    if(s[i] == 'R'){
      vv[0][i+1] = vv[0][i] + 1;
    }else{
      vv[0][i+1] = vv[0][i];
    }
    if(s[i] == 'G'){
      vv[1][i+1] = vv[1][i] + 1;
    }else{
      vv[1][i+1] = vv[1][i];
    }
    if(s[i] == 'B'){
      vv[2][i+1] = vv[2][i] + 1;
    }else{
      vv[2][i+1] = vv[2][i];
    }
  }
  long long ans = 0;
  rep(i, 0, n){
    rep(j, i+1, n){
      if (s[i] == s[j]) continue;

      if(s[i] != 'R' && s[j] != 'R'){
        ans += vv[0][n] - vv[0][j+1];
        if(s[2 * j - i] != 'R') ans--;
      }
      if(s[i] != 'G' && s[j] != 'G'){
        ans += vv[1][n] - vv[1][j+1];
        if(s[2 * j - i] != 'G') ans--;
      }
      if(s[i] != 'B' && s[j] != 'B'){
        ans += vv[2][n] - vv[2][j+1];
        if(s[2 * j - i] != 'B') ans--;
      }
    }
  }

  cout << ans << endl;
  return 0;
  }