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

using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, n, r) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD-a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= MOD; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
int in() {int x; cin>>x; return x;}
string stin() {string s; cin>>s; return s;}
int RGBtoInt(char c) {
  if(c == 'R') return 0;
  if(c == 'G') return 1;
  if(c == 'B') return 2;
}
char InttoRGB(int a) {
  if(a == 0) return 'R';
  if(a == 1) return 'G';
  if(a == 2) return 'B';
}
int red_count[4005];
int green_count[4005];
int blue_count[4005];
/***** MAIN *****/
signed main() {
  int n = in();
  string s = stin();
  REP(i,n) {
    if(s[i] == 'R') red_count[i] = 1;
    else if(s[i] == 'G') green_count[i] = 1;
    else blue_count[i] = 1;
  }
  REPRS(i,n-2,0) {
    red_count[i] += red_count[i+1];
    green_count[i] += green_count[i+1];
    blue_count[i] += blue_count[i+1];
  }
  int ans = 0;
  REP(i,n-2) {
    int first = RGBtoInt(s[i]);
    REPS(j,1,n-1) {
      int second_index = i+j;
      if(second_index >= n-1) break;
      int second = RGBtoInt(s[second_index]);
      if(first == second) continue;
      char rest_char = InttoRGB(3-first-second);
      if(rest_char == 'R') {
        ans += red_count[second_index+1];
      } else if(rest_char == 'G') {
        ans += green_count[second_index+1];
      } else {
        ans += blue_count[second_index+1];
      }
      if(second_index + j <= n-1) {
        if(s[second_index + j] == rest_char) {
          --ans;
        }
      }
    }
  }
  cout << ans;
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 3704