#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
#define rep(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
#define PI 3.14159265358979
typedef long long int ll;
const int inf=1001001001;
ll absc(ll a,ll b){return (a-b>0?a-b:b-a);
}
ll mini(ll a,ll b){return (a>b?b:a);}
ll gcd(ll a,ll b){
	if(a<b)swap(a,b);
	return (a%b?gcd(a%b,b):b);
}
int main()
{
    ll N,ans=0;
    string s;
    cin>>N;
    cin>>s;
    for(int i=0;i<N-3;i++)
    {
    	for(int j=i+1;j<N-1;j++)
    	{
    		for(int k=j+1;k<N;k++)
    		{
    			if(s[i]!=s[j]&&s[j]!=s[k]&&s[k]!=s[i]&&j-i!=k-j)++ans;
    		}
    	}
    }
    cout<<ans;
}
