#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <math.h>

int main(void)
{
    int n;
    char s[5000] = {};
    scanf("%d", &n);
    scanf("%s", s);

    int r, g, b;
    int i, ii;
    r = 0;
    g = 0;
    b = 0;
    long int a;

    i = -1;
    while (s[++i])
    {
        if (s[i] == 'R')
            r++;
        else if (s[i] == 'G')
            g++;
        else if (s[i] == 'B')
            b++;
    }

    a = r * g * b;

    for (i = 1; i < n; i++)
    {
        ii = 0;
        while (ii + 2 * i < n)
        {
            if (s[ii] != s[ii + i] && s[ii + i] != s[ii + 2 * i] && s[ii] != s[ii + 2 * i])
                a--;
            ii++;
        }
    }
    printf("%d", a);

    return (0);
}
