#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;
string s;
ll ans; 
int main()
{
	cin>>n>>s;
	for(int i=n-1;i>=2;i--)
	{
		s[1]=s[i];
		for(int j=i-1;j>=1;j--)
		{
			s[2]=s[j];
			if(s[1]==s[2])continue;
			for(int l=0;l<=j-1;l++)
			if(s[l]!=s[1]&&s[l]!=s[2]&&s[l]!=(2*j-i))ans++;
		}
	}
	cout<<ans;
return 0;
}
