#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ull = unsigned long long;

#define int long long
#define FOR(a, b, c) for(int a = b, _c = c; a <= _c; ++a)
#define ROF(a, b, c) for(int a = b, _c = c; a >= _c; --a)
#define REP(a, b, c) for(int a = b, _c = c; a < _c; ++a)
#define VEC(a, b) for(auto &a : b)
#define ii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define all(a) a.begin(), a.end()
#define reset(f, x) memset(f, x, sizeof(f))
#define sz(x) (int)(x.size())
#define bit(x, i) (x >> (i - 1) & 1ll)
#define onbit(x, i) (x | (1ll << (i - 1)))
#define offbit(x, i) (x & ~(1ll << (i - 1)))

template <class T> void Max(T &x, T y) { x = (x > y) ? x : y;}
template <class T> void Min(T &x, T y) { x = (x < y) ? x : y;}

#define debug(x) cerr << #x << '=' << x << '\n'
#define debugn(a, n) FOR(i, 1, n) cerr << a[i] << ' '
#define debugv(a) VEC(v, a) cerr << v << ' '

const int N = 4005;
int n;
string s;

main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  cin >> n >> s;
  s = ' ' + s;
  int x = 0, y = 0, z = 0;
  FOR(i, 1, n) {
    if(s[i] == 'R') x++;
    if(s[i] == 'G') y++;
    if(s[i] == 'B') z++;
  }
  int ans = x * y * z;
  FOR(i, 1, n) {
    FOR(j, i + 1, n) {
        int dis = j - i;
        int k = i + 2 * dis;
        if(k > n) continue;
        bool ok1 = 0, ok2 = 0, ok3 = 0;
        if(s[i] == 'R' || s[j] == 'R' || s[k] == 'R') ok1 = 1;
        if(s[i] == 'G' || s[j] == 'G' || s[k] == 'G') ok2 = 1;
        if(s[i] == 'B' || s[j] == 'B' || s[k] == 'B') ok3 = 1;
        ans -= (ok1 & ok2 & ok3);
    }
  }
  cout << ans << '\n';
}
