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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 4e3 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

char s[maxn];
int cnt[maxn][3];
int pos[26];
char st[] = {'R', 'G', 'B'};

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);
//  freopen(Task".out", "w", stdout);

  int n; cin >> n;
  cin >> s + 1;

  For (i, 0, 2){
    pos[st[i] -'A'] = i;
  }

  For(i, 1, n) For(j, 0, 2){
    cnt[i][j] = cnt[i-1][j];
    if (s[i] == st[j]) ++cnt[i][j];
  }
  int ans = 0;
  For(i, 1, n - 2) For (j, i + 1, n - 1){
    if (s[i] == s[j]) continue;
    int k = 3 - pos[s[i]-'A'] - pos[s[j]-'A'];
    ans += cnt[n][k] - cnt[j][k];
    int dif = j - i;
    if (j + dif <= n && pos[s[j+dif]-'A'] == k) --ans;
  }
  cout << ans;

}

