#include <iostream>
#include <string>
#include <vector>

using namespace std;

int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }

int main(){
    int N; cin >> N;
    vector<char> S(N);
    long long ans = 0;
    int r = 0;
    int  g = 0;
    int b = 0;
    long long dec = 0;

    for (int l = 0; l < N; l++)
    {
      cin >> S[l];
      if (S[l] == 'R') r++;
      if (S[l] == 'G') g++;
      if (S[l] == 'B') b++;
    }

    for (int i = 0; i < N-2; i++)
    {
      for (int j = i+1; j < N-1; j++)
      {
        int d = j-i;
        if ((S[i]!=S[j]) && (S[i]!=S[j+d]) && (S[j]!=S[j+d]) && (j+d < N)) dec++;
      }
    }

    ans = (r*g*b) - dec;
    
    cout << ans << endl;
    return 0;
    
}