#include <iostream>
#include <stdio.h>
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(){
    int n;
    int r=0;
    int g=0;
    int b=0;
    cin>>n;
    char color[n];
    for (int i=0; i<n; i++){
        cin>>color[i];
        if (color[i]=='R') r+=1;
        if (color[i]=='G') g+=1;
        if (color[i]=='B') b+=1;
        
    }
    
    
    int count=0;
    for (int i=0; i<n-1; i++){
        for (int k=i+1; k<n; k++){
            if ((i+k)%2==1){
                continue;
            }
            
            int j=(i+k)/2;
            
            if (color[i]!=color[j] && color[j]!=color[k] && color[i]!=color[k]){
                count+=1;
            }
        }
    }
    
    cout<<r*g*b-count<<endl;
}