#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);

    // 全てのRGBの順列
    int i;
    int r = 0, g = 0, b = 0;
    for (i = 0; i < N; i++) {
        if (S[i] == 'R') r++;
        if (S[i] == 'G') g++;
        if (S[i] == 'B') b++;
    }
    long long result = r * g * b;

    // 距離が同じでRGBなら除外
    // long long exc = 0;
    // int head, center, tail;
    // for (head = 0; head < N - 2; head++) {
    //     for (center = head + 1; center < N - 1; center++) {
    //         tail = center * 2 - head;
    //         if (tail > N - 1) break;
    //         if (check(S[head], S[center], S[tail])) {
    //             exc++;
    //         }
    //     }
    // }
    int head = 0;
    int center = 1;
    int tail = 2;
    while (head < N - 2) {
        if (check(S[head], S[center], S[tail])) {
            // exc++;
            result--;
        }
        center += 1;
        tail += 2;
        if (tail > N - 1) {
            head++;
            center = head + 1;
            tail = head + 2;
        }
    }

    // printf("%lld\n", exc);
    printf("%lld\n", result);
    return 0;
}