#include <stdio.h>

int main()
{
    int n;
    char s[4001];
    int rgb_buc[3][4001];
    scanf("%d %s",&n,s);

    int i,j,k;

    long long ans = 0;
    for (i = 0; i < n; i++)
    {
        for (j = i + 1; j < n; j++)
        {
            if(s[i] == s[j])continue;
            for (k = j + 1; k < n; k++)
            {
                if((s[i] == s[k] || s[j] == s[k]) || (j - i == k - j))continue;
                ans++;
            }
        }
    }
    printf("%lld",ans);
}
