#include <stdio.h>

int readG(char S[4001], int i, int j, int N)
{
  	int	k;
  	int sumG;
  	
  	sumG = 0;
  	for(k=i+1; k<N; k++)
    {
      	if(S[k] == 'G')
        {  
      		if(k - i == i - j)
          		continue ;
      		else
          		sumG++;
        }
    }
  	return (sumG);
}

int readB(char S[4001], int i, int j, int N)
{
  	int	k;
  	int sumB;
  	
  	sumB = 0;
  	for(k=i+1; k<N; k++)
    {
      	if(S[k] == 'B')
        {  
      		if(k - i == i - j)
          		continue ;
      		else
          		sumB++;
        }
    }
  	return (sumB);
}

int readR(char S[4001], int i, int j, int N)
{
  	int	k;
  	int sumR;
  	
  	sumR = 0;
  	for(k=i+1; k<N; k++)
    {
      	if(S[k] == 'R')
        {  
      		if(k - i == i - j)
          		continue ;
      		else
          		sumR++;
        }
    }
  	return (sumR);
}

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

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

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

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

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

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

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

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