#include <stdio.h>

int check(char a, char b, char c)
{
    if (a != b && a != c && b != c) {
        return 1;
    }
    return 0;
}

int main(void)
{
    int N;
    char S[4001];
    scanf("%d", &N);
    scanf("%s", S);

    int i = 0;
    int r = 0, g = 0, b = 0;
    while (S[i] != '\0') {
        if (S[i] == 'R') {
            r++;
        } else if (S[i] == 'G') {
            g++;
        } else if (S[i] == 'B') {
            b++;
        }
        i++;
    }
    unsigned long long result = (unsigned long long)(r * g * b);

    int head, center, tail, dist;
    for (head = 0; head < N; head++) {
        for (dist = 1; dist < N; dist++) {
            if (head + dist * 2 >= N) {
                break;
            }
            center = head + dist;
            tail = head + dist * 2;
            if (check(S[head], S[center], S[tail])) {
                result--;
            }
        }
    }
    printf("%lld\n", result);
    return 0;
}