#include<bits/stdc++.h>
#define ll long long 
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
#define pi pair<int,int>
using namespace std;
int main(){
	ios_base::sync_with_stdio(0) ; 
	cin.tie(0) ;
     int n ; 
     cin>> n ; 
     string s ;
     cin>> s;
     int a[s.length()+1] ;
     for(int i = 0; i < n; ++i){
		 if(s[i] == 'R')
		     a[i] = 1 ; 
		 else if(s[i] == 'G')
		   a[i] = 2 ;
		   else
		   a[i] = 3 ; 
	   }
	   int co1 = 0 , co2 = 0, co3 = 0;
	   int arr1[n] = {0} , arr2[n] = {0}  , arr3[n] = {0} ; 
	   memset(arr2 , 0 , sizeof arr2) ; 
	   memset(arr3 , 0 , sizeof arr3) ; 
	   memset(arr1 , 0 , sizeof arr1)  ;
	   ll ans =  0 ; 
	   for(int i = 0 ; i < n ; ++i){
		   if(a[i] == 1){
		   co1++;
		   arr1[i] = co1 ;
		   if(i > 0 ){ 
		   arr2[i] = arr2[i-1] ; 
		   arr3[i] = arr3[i-1] ; }
	      }
		  else if(a[i] == 2){
		   co2++ ;
		   arr2[i] = co2 ; 
		   if(i > 0 ){
		   arr1[i] = arr1[i-1] ; 
		   arr3[i] =arr3[i-1] ; }
	   }
		 else  if(a[i] == 3){
		   co3++ ;
		   arr3[i] = co3 ;
		   if(i > 0){
		   arr1[i] = arr1[i-1] ; 
		   arr2[i] = arr2[i-1] ; }
	   }
   }
  /* cout<<arr1[n-1]<<endl;
   cout<<arr2[n-1]<<endl;
   cout<<arr3[n-1]<<endl;
   */
   for(int i = 1; i < n -1; ++i){
	    if(a[i] == 1){
		
		  for(int j = i - 1 , count=1; j >=0 && i + count < n ; --j , count++ ) {
			   if((a[j] == 2 &&a[i+count] == 3) ||
			       (a[j] == 3 && a[i + count ]==2)) ans-- ; 
			   }
		int fno2 = arr2[i] ; 
		int sno2 = arr2[n-1]  - arr2[i] ; 
		int sno3 = arr3[n-1] - arr3[i] ; 
		int fno3 = arr3[i] ;
			ans = ans + fno2*sno3+
			        sno2*fno3 ; 
				}
	   else if(a[i] == 2){
		   
		   
		  for(int j = i - 1 , count=1; j >=0 && i + count < n ; --j , count++ ) {
			   if((a[j] == 1 &&a[i+count] == 3 )||
			       (a[j] == 3 && a[i + count] ==1)) ans-- ; 
			   }
		   int sno3 = arr3[n-1] - arr3[i] ; 
           int fno3 = arr3[i] ;
		   int fno1 = arr1[i] ; 
		   int sno1 = arr1[n-1] - arr1[i] ; 
		   ans = ans + fno1*sno3 + 
		              fno3 * sno1 ; 
				  }
	  else{
		  for(int j = i - 1 , count=1; j >=0 && i + count < n ; --j , count++ ) {
			   if((a[j] == 2 &&a[i+count] == 1) ||
			       (a[j] == 1 && a[i + count] ==2)) ans-- ; 
			   }
		  int fno1 = arr1[i] ; 
		   int sno1 = arr1[n-1] - arr1[i] ; 
		   int fno2 = arr2[i] ; 
		int sno2 = arr2[n-1]  - arr2[i] ; 
		
		   
		  ans = ans + fno1*sno2 +
		              fno2*sno1 ;
			  }
		  }
		   
 
  
  
  
  cout<<ans<<endl;
  
  
  
  
  
  
}
