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

typedef long long LL;
typedef long double LD;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;
typedef pair<LD, LD> PDD;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define dbl(k, x) fixed << setprecision(k) << (x)

template <typename _T>
inline void _DBG(const char *s, _T x) {
  cerr << s << " = " << x << "\n";
}
template <typename _T, typename... args>
void _DBG(const char *s, _T x, args... a) {
  while (*s != ',') cerr << *s++;
  cerr << " = " << x << ',';
  _DBG(s + 1, a...);
}

#define _upgrade                \
  ios_base::sync_with_stdio(0); \
  cin.tie(0);                   \
  cout.tie(0);
#define DBG(...) _DBG(#__VA_ARGS__, __VA_ARGS__)

// ********************** CODE ********************** //

int main() {
  _upgrade;
  int n;
  string s;
  cin >> n >> s;

  vector<int> prefix_sum_r(n + 1);
  vector<int> prefix_sum_g(n + 1);
  vector<int> prefix_sum_b(n + 1);
  for (int i = 1; i < n + 1; i++) {
    prefix_sum_r[i] = prefix_sum_r[i - 1];
    prefix_sum_g[i] = prefix_sum_g[i - 1];
    prefix_sum_b[i] = prefix_sum_b[i - 1];
    if (s[i - 1] == 'R') {
      prefix_sum_r[i]++;
    }
    if (s[i - 1] == 'G') {
      prefix_sum_g[i]++;
    }
    if (s[i - 1] == 'B') {
      prefix_sum_b[i]++;
    }
  }

  LL res = 0;

  for (int i = 0; i < n; i++) {
    if (s[i] != 'R') {
      continue;
    }
    for (int j = i + 1; j < n; j++) {
      if (s[j] != 'G') {
        continue;
      }
      res += prefix_sum_b[n] - prefix_sum_b[j + 1];
      if (j + (j - i) < n && s[j + (j - i)] == 'B') {
        res--;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (s[i] != 'R') {
      continue;
    }
    for (int j = i + 1; j < n; j++) {
      if (s[j] != 'B') {
        continue;
      }
      res += prefix_sum_g[n] - prefix_sum_g[j + 1];
      if (j + (j - i) < n && s[j + (j - i)] == 'G') {
        res--;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (s[i] != 'G') {
      continue;
    }
    for (int j = i + 1; j < n; j++) {
      if (s[j] != 'R') {
        continue;
      }
      res += prefix_sum_b[n] - prefix_sum_b[j + 1];
      if (j + (j - i) < n && s[j + (j - i)] == 'B') {
        res--;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (s[i] != 'G') {
      continue;
    }
    for (int j = i + 1; j < n; j++) {
      if (s[j] != 'B') {
        continue;
      }
      res += prefix_sum_r[n] - prefix_sum_r[j + 1];
      if (j + (j - i) < n && s[j + (j - i)] == 'R') {
        res--;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (s[i] != 'B') {
      continue;
    }
    for (int j = i + 1; j < n; j++) {
      if (s[j] != 'G') {
        continue;
      }
      res += prefix_sum_r[n] - prefix_sum_r[j + 1];
      if (j + (j - i) < n && s[j + (j - i)] == 'R') {
        res--;
      }
    }
  }

  for (int i = 0; i < n; i++) {
    if (s[i] != 'B') {
      continue;
    }
    for (int j = i + 1; j < n; j++) {
      if (s[j] != 'R') {
        continue;
      }
      res += prefix_sum_g[n] - prefix_sum_g[j + 1];
      if (j + (j - i) < n && s[j + (j - i)] == 'G') {
        res--;
      }
    }
  }

  cout << res << "\n";
  return 0;
}

Measured memory_bytes: 3648