/* In the name of Allah */
#include <bits/stdc++.h>
using namespace std;
// const int INF = 20000000;
#define ll long long
#define _SetBit(A, k) (A[(k / 32)] |= (1 << (k % 32)))
#define _ClearBit(A, k) (A[(k / 32)] &= ~(1 << (k % 32)))
#define _CheckBit(A, k) (A[(k / 32)] & (1 << (k % 32)))
#define SetBit(x, k) (x |= (1 << k))
#define ClearBit(x, k) (x &= ~(1 << k))
#define CheckBit(x, k) (x & (1 << k))
int vis[26];
int main()
{
  int n;
  cin >> n;
  char x[n + 1];
  ll r = 0, g = 0, b = 0;
  for (int i = 0; i < n; i++)
  {
    cin >> x[i];
    if (x[i] == 'R')
      r++;
    else if (x[i] == 'G')
      g++;
    else
      b++;
  }
  ll cnt = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = 0; j < (n - i + 1) / 2; j++)
    {
      if (x[i] != x[i + j] && x[i + j] != x[i + 2 * j] && x[i] != x[i + 2 * j])
        cnt++;
    }
  }
  ll res = r * g * b;
  res -= cnt;
  // cout << "**" << r << " " << g << " " << b << " " << cnt << ":\n";
  cout << res << "\n";
  return 0;
}