#include<stdio.h>
#include <string.h>
#include<iostream>
using namespace std;
 
int main()
{
    int N;
  	int sum=0;
  	char *str;
  	int R_num=0,G_num=0,B_num=0;
	int R[4000], G[4000], B[4000];

  	cin>>N;
      
    //vector<char> vec(N);
  
  	cin>>str;
      
  	for (int i = 0; i < N; i++) {
      if(str[i]=='R'){
        R[R_num]=i;
        R_num++;
      }else if(str[i]=='G'){
        G[G_num]=i;
        G_num++;
      }else if(str[i]=='B'){
        B[B_num]=i;
        B_num++;
      }
  	}
 

  	for (int i = 0; i < R_num; i++) {
        	for (int j = 0; j < G_num; j++) {
                	for (int k = 0; k < B_num; k++) {
                    	int a=R[i],b=G[j],c=B[k];
                      	if(a<b){
                          	int temp;
                      		temp=a;
                      		a=b;
                      		b=temp;
                        }
                      	if(b<c){
                          	int temp;
                      		temp=c;
                      		c=b;
                      		b=temp;
                      		if(a<c){
                          		int temp;
                      			temp=a;
                      			a=c;
                      			c=temp;
                        	}        
                        }
                      if(a-b!=b-c)  
                        sum++;
                    }
            }
    }

  	cout<<sum<<endl;
  
    return 0;
}