#include <stdio.h>
int main(void)
{
	int num, i, j, k, flag;
	char s[4001] = { 0 };
	long long int rn = 0, gn = 0, bn = 0, ans = 0;
	scanf("%d", &num);
	scanf("%s", s);
	for (i = 0; i < num; i++) {
		if (s[i] == 'R')
			rn++;
		else if (s[i] == 'G')
			gn++;
		else if (s[i] == 'B')
			bn++;
	}
	ans = rn * gn * bn;
 
	for (i = 0; i < num; i++) {
        if(1+n*2>num)
          break;
		for (j = i + 1; j < num; j++) {
			if ((j - i)*2 > num)
				break;
			for (k = j + 1; k < num; k++) {
				if ((s[i] != s[j] && s[j] != s[k]) && s[i] != s[k])
					if (j - i == k - j)
						ans--;
            }
        }
    }
			printf("%lld\n", ans);
			return 0;
		}