#include <stdio.h>
#include <stdlib.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;

int main(void)
{
    int n;
    char s[4001];
    ll del = 0, r = 0, g = 0, b = 0, ans;
    char pre[2][2], cnt = 0;
    scanf("%d%s", &n, s);
    rep(i, n)
    {
        switch (s[i])
        {
        case 'R':
            r++;
            break;
        case 'G':
            g++;
            break;
        case 'B':
            b++;
            break;
        }
    }
    for (int i = 1; i < n; i++)
    {
        if (1 + i * 2 > n)
            break;
        rep(j, n - i * 2)
        {
            if (j + i * 2 > n)
                break;
            if (s[j] != s[j + i] && s[j] != s[j + i * 2] && s[j + i] != s[j + i * 2])
                del++;
        }
    }

    ans = r * g * b - del;
    printf("%lld\n", ans);
    return 0;
}