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

int main() {
  int n, r = 0, g = 0, b = 0;
  string s;
  cin >> n >> s;

  for (int i = 0; i < n; i++) {
    if (s[i] == 'R') r++;
    if (s[i] == 'G') g++;
    if (s[i] == 'B') b++;
  }

  int c = 0;
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (s[i] != s[j]) {
        for (int k = j + 1; k < n; k++) {
          if (s[i] != s[k] && s[j] != s[k] && (k - j == j - i)) c++;
        }
      }
    }
  }

  cout << r * g * b - c << endl;
}