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

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << " : " << arg1 << "\n";
}
template <typename Arg1, typename... Args>
void __f(const char* na, Arg1&& arg1, Args&&... args) {
  const char* c = strchr(na + 1, ',');
  cerr.write(na, c - na) << " : " << arg1 << " , ";
  __f(c + 1, args...);
}
#define endl "\n"
#define all(v) v.begin(), v.end()
#define UNIQUE(v) sort(all(v)),v.erase(unique(all(v)),v.end())
typedef long long LL;
typedef pair <int,int> pii;
const double pi = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9 + 7;
const int inf = 1e9;
const LL INF = 1e18;
const int N = 4e3 + 5;

int a[ N ];
int sum[ N ][ 5 ];
int n;

int get_sum(int l, int r, int id) {
  if (l > r) return 0;
  r = min(r, n);
  return sum[r][id] - sum[l - 1][id];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("input.txt", "r", stdin);
  #endif // LOCAL
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    int id = 0;
    if (s[i] == 'R') id = 1;
    if (s[i] == 'G') id = 2;
    if (s[i] == 'B') id = 3;
    a[i + 1] = id;
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 3; j++) {
      sum[i][j] += sum[i - 1][j] + (a[i] == j);
    }
  }
  LL ans = 0;
  for (int i = 1; i < n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (a[i] == a[j]) continue;
      int id = 6 - a[i] - a[j];
      int d = j - i;
      int idx = j + d;
      ans += get_sum(j + 1, idx - 1, id) + get_sum(idx + 1, n, id);
    }
  }
  cout << ans << endl;
  return 0;
}

