#include <stdio.h>
int main(void)
{
	int i, j, k;
	int cnt = 0, N;
	char aa[4000 + 2];
	int R[4000 + 2], G[4000 + 2], B[4000 + 2];
	int Rcnt = 0, Gcnt = 0, Bcnt = 0;
	scanf("%d", &N);
	for (i = 0; i < N; i++)
	{
		scanf("%s", &aa[i]);
	}
	for (i = N; i > 0; i--)
	{
		if(aa[i]=='R'){
			Rcnt++;
		}
		else if (aa[i] == 'G')
		{
			Gcnt++;
		}
		else if (aa[i] == 'B')
		{
			Bcnt++;
		}
		R[i] = Rcnt;
		G[i] = Gcnt;
		B[i] = Bcnt;
	}

		//	strcpy(bb,aa);
		//	strcpy(cc,aa);
		//	printf("%s\n%s\n",bb,cc);
		for (i = 0; i < N; i++)
		{
			for (j = i + 1; j < N; j++)
			{
				if (aa[i] == aa[j])
				{
					continue;
				}
				for (k = j + 1; k < N; k++)
				{
					if (aa[i] == 'R' && aa[j] == 'G')
					{
						cnt+=B[k];
					}
					if (aa[i] == 'R' && aa[j] == 'B')
					{
						cnt += G[k];
					}
					else{
						cnt += R[k];
					}
					if (j - i != k - j)
					{
						cnt--;
					}
					break;
				}
			}
		}
		printf("%d\n", cnt);
		return 0;
	}