#include <bits/stdc++.h>
#define RI register int
typedef long long LL;
#define int LL

#define FILEIO(name) freopen(name".in", "r", stdin), freopen(name".out", "w", stdout);

using namespace std;

int const MAXN = 4005;
char s[MAXN];
int sum[3][MAXN];

signed main() {
  
#ifdef LOCAL
  FILEIO("a");
#endif

  int n; cin >> n;
  cin >> (s + 1);
  for (RI i = 1; i <= n; ++i)
    if (s[i] == 'R') ++sum[0][i];
    else if (s[i] == 'G') ++sum[1][i];
    else ++sum[2][i];
  for (RI i = 1; i <= n; ++i) {
    sum[0][i] += sum[0][i - 1];
    sum[1][i] += sum[1][i - 1];
    sum[2][i] += sum[2][i - 1];
  }
  int ans = 0;
  for (RI i = 1; i <= n; ++i)
    for (RI j = i + 1; j <= n; ++j)
      if (s[i] != s[j]) {
        int tmp = 'R' + 'G' + 'B' - s[i] - s[j];
        if (tmp == 'R') {
          ans += sum[0][i - 1];
          int dis = j - i;
          if (i - dis > 0 && s[i - dis] == 'R') --ans;
        }
        if (tmp == 'G') {
          ans += sum[1][i - 1];
          int dis = j - i;
          if (i - dis > 0 && s[i - dis] == 'G') --ans;
        }
        if (tmp == 'B') {
          ans += sum[2][i - 1];
          int dis = j - i;
          if (i - dis > 0 && s[i - dis] == 'B') --ans;
        }
      }
  cout << ans;

  return 0;
}

// created by Daniel yuan
