#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define reps(i,a,b) for(int i= a; i < b; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int n;
  string s;
  cin >> n >> s;
  ll r = 0, b = 0, g = 0;
  rep(i, n) {
    if (s.at(i) == 'R') {
      r++;
      continue;
    }
    if (s.at(i) == 'G') {
      g++;
      continue;
    }
    if (s.at(i) == 'B') {
      b++;
      continue;
    }
  }
  ll ans = r * b * g;
  if (!ans) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, n) {
    reps(j, i+1, n) {
      if (s.at(i) == s.at(j)) continue;

      int k = 2*j - i;
      if (k >= n) continue;
      if ((s.at(i) != s.at(j)) && (s.at(i) != s.at(k)) && (s.at(k) != s.at(j))) {
        ans--;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"

using namespace std;

using u8 = uint8_t;
using u16 = uint16_t;
using u32 = uint32_t;
using u64 = uint64_t;
using i8 = int8_t;
using i16 = int16_t;
using i32 = int32_t;
using i64 = int64_t;

constexpr char newl = '\n';
constexpr double eps = 1e-10;

#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define F0R(i,b) FOR(i,0,b)
#define RFO(i,a,b) for (int i = ((b)-1); i >=(a); i--)
#define RF0(i,b) RFO(i,0,b)
#define fi first
#define se second
#define debug(x) cout << #x << ": " << x << '\n';
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()

template<typename T1, typename T2> inline void chmin(T1& a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
template<class T> void Print(vector<T> v) {
  F0R(i, v.size()) {
    cout << v[i] << ' ';
  }
  cout << newl;
}

#if 1


// INSERT ABOVE HERE
signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int N, L;
  cin >> N >> L;

  int l = L, r = L + N - 1;
  int sum = (l+r) * N / 2;
  if (l > 0) {
    sum -= l;
  }
  else if (r < 0) {
    sum -= r;
  }

  cout << sum;
}
#endif
