#include <stdio.h>

int readB(char S[4001], int i, int j, int N)
{
  	int	k;

  	for(k=j+1; k<N; k++)
    {
      	if(S[k] == 'B')
        {  
      		if(k - j == j - i)
      		{
      		    return (1);
      		}
        }
    }
  	return (0);
}

int readR(char S[4001], int i, int j, int N)
{
  	int	k;

  	for(k=j+1; k<N; k++)
    {
      	if(S[k] == 'R')
        {  
      		if(k - j == j - i)
      		{
      		    return (1);
      		}
        }
    }
  	return (0);
}

int readG(char S[4001], int i, int j, int N)
{
  	int	k;

  	for(k=j+1; k<N; k++)
    {
      	if(S[k] == 'G')
        {  
      		if(k - j == j - i)
      		{
      		    return (1);
      		}
        }
    }
  	return (0);
}

long long readBG(char S[4001], int i, int N)
{
  	int	j;
  	long long sum;

    sum = 0;
  	for(j=i+1; j<N; j++)
    {
      	if(S[j] == 'B')
          	sum += readG(S, i, j, N);
      	else if(S[j] == 'G')
          	sum += readB(S, i, j, N);
    }
    return (sum);
}

long long readRB(char S[4001], int i, int N)
{
  	int	j;
  	long long sum;

    sum = 0;
  	for(j=i+1; j<N; j++)
    {
      	if(S[j] == 'R')
          	sum += readB(S, i, j, N);
      	else if(S[j] == 'B')
          	sum += readR(S, i, j, N);
    }
    return (sum);
}

long long readRG(char S[4001], int i, int N)
{
  	int	j;
  	long long sum;

    sum = 0;
  	for(j=i+1; j<N; j++)
    {
      	if(S[j] == 'R')
          	sum += readG(S, i, j, N);
      	else if(S[j] == 'G')
          	sum += readR(S, i, j, N);
    }
    return (sum);
}

int	main(void)
{
  	int	N;
  	char S[4001];
 	int	i;
 	long long sum;
 	int R;
 	int G;
 	int B;
  
  	scanf("%d", &N);
    scanf("%s", S);

    R = 0;
    G = 0;
    B = 0;
    sum = 0;
  	for(i=0; i<N; i++)
    {
      	if(S[i] == 'R')
      	{
      	    R++;
          	sum += readBG(S, i, N);
      	}
      	else if(S[i] == 'G')
        {
            G++;
            sum += readRB(S, i, N);
        }
      	else
      	{
      	    B++;
          	sum += readRG(S, i, N);
      	}
    }
    printf("%lld", R * G * B - sum);
  	return(0);
}