#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#define ll long long
int abs(int a)
{
    return (a < 0) ? -a : a;
}
int main(void)
{
    int r[4000];
    int g[4000];
    int b[4000];
    int n, i, j, k, count = 0;
    int R, G, B;
    R = G = B = 0;
    char s[4000];
    scanf("%d", &n);
    scanf("%s", s);
    for (i = 0; i < strlen(s); i++) //文字列の読み込み
    {
        if (s[i] == 'R')
        {
            r[R] = i;
            R++;
        }
        else if (s[i] == 'G')
        {
            g[G] = i;
            G++;
        }
        else
        {
            b[B] = i;
            B++;
        }
    }
    if (R == 0 || G == 0 || B == 0)
    { //欠けがあったら解なし
        printf("0\n");
        return 0;
    }
    for (i = 0; i < R; i++)
    {
        for (j = 0; j < G; j++)
        {
            if (r[i] < g[j])
            {
                for (k = 0; k < B; k++)
                {
                    if (b[k] < r[i])
                    {
                        if (r[i] - b[k] == g[j] - r[i])
                            continue;
                        count++;
                    }
                    else if (b[k] > g[j])
                    {
                        if (g[j] - r[i] == b[k] - g[j])
                            continue;
                        count++;
                    }
                    else
                    {
                        if (b[k] - r[i] == g[j] - b[k])
                            continue;
                        count++;
                    }
                }
            }
            else
            {
                for (k = 0; k < B; k++)
                {
                    if (b[k] < g[j])
                    {
                        if (g[j] - b[k] == r[i] - g[j])
                            continue;
                        count++;
                    }
                    else if (b[k] > r[i])
                    {
                        if (r[i] - g[j] == b[k] - r[i])
                            continue;
                        count++;
                    }
                    else
                    {
                        if (b[k] - g[j] == r[i] - b[k])
                            continue;
                        count++;
                    }
                }
            }
        }
    }

    //printf("%d %d %d\n", j, k, l);
    printf("%d\n", count);
    return 0;
}