#include <inttypes.h>
#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    intmax_t N;
    char S[4001];
    intmax_t rs[4001] = {}, gs[4001] = {}, bs[4001] = {};
    size_t rn = 0, gn = 0, bn = 0;
    intmax_t ans = 0;

    scanf("%jd", &N);
    scanf("%s", S);

    if (S[0] == 'R') {
        rn++;
        rs[0]++;
    } else if (S[0] == 'G') {
        gn++;
        gs[0]++;
    } else if (S[0] == 'B') {
        bn++;
        bs[0]++;
    }

    for (size_t i = 1; i < N; i++) {
        rs[i] = rs[i - 1];
        gs[i] = gs[i - 1];
        bs[i] = bs[i - 1];
        if (S[i] == 'R') {
            rn++;
            rs[i]++;
        } else if (S[i] == 'G') {
            gn++;
            gs[i]++;
        } else if (S[i] == 'B') {
            bn++;
            bs[i]++;
        }
    }

    for (size_t i = 0; i < N; i++) {
        if (S[i] == 'R') {
            for (size_t j = i + 1; j < N; j++) {
                if (S[j] == 'G') {
                    ans += bn - bs[j];
                    if ((j + (j - i) < N) && (S[j + (j - i)] == 'B'))
                        ans--;
                } else if (S[j] == 'B') {
                    ans += gn - gs[j];
                    if ((j + (j - i) < N) && (S[j + (j - i)] == 'G'))
                        ans--;
                }
            }
        } else if (S[i] == 'G') {
            for (size_t j = i + 1; j < N; j++) {
                if (S[j] == 'R') {
                    ans += bn - bs[j];
                    if ((j + (j - i) < N) && (S[j + (j - i)] == 'B'))
                        ans--;
                } else if (S[j] == 'B') {
                    ans += rn - rs[j];
                    if ((j + (j - i) < N) && (S[j + (j - i)] == 'R'))
                        ans--;
                }
            }
        } else if (S[i] == 'B') {
            for (size_t j = i + 1; j < N; j++) {
                if (S[j] == 'R') {
                    ans += gn - gs[j];
                    if ((j + (j - i) < N) && (S[j + (j - i)] == 'G'))
                        ans--;
                } else if (S[j] == 'G') {
                    ans += rn - rs[j];
                    if ((j + (j - i) < N) && (S[j + (j - i)] == 'R'))
                        ans--;
                }
            }
        }
    }

    printf("%jd\n", ans);

    return 0;
}
