#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
typedef int64_t Int;

int main(){ 
  int N, t, r, g, b, C;
  cin >> N;
  string S;
  cin >> S;
  t = 0;
  r = 0;
  g = 0;
  b = 0;

  rep(i,N) {
      if (S[i] == 'R') r++;
      else if (S[i] == 'G') g++;
      else if (S[i] == 'B') b++;
  }


  C = r * g * b;
  
  rep(i,N-2) {
    for (int j = i + 1; 2 * j < N + i; j++) {
      if (S[i] != S[j] && S[i] != S[2 * j - i] && S[j] != S[2 * j - i]) t++; 
    }
  }

  cout << C - t << endl;

}