#include<bits/stdc++.h>
using namespace std;
int n,m,ans;
char s[40005];
map<char,int>mp;
int main()
{
    long long ans=0;
    scanf("%d",&n);
    scanf("%s",s+1);
    for(int i=1;i<=n;i++)
    {
        mp[s[i]]++;
        for(int i0=i+1;i0<=n;i0++)
        {
            if(s[i]==s[i0])continue;
            int d=i-mp[s[i]]-mp[s[i0]],p=i0-i;
            if(i-p>=1&&s[i-p]!=s[i]&&s[i-p]!=s[i0])d--;
            ans+=d;
        }
    }
    printf("%lld\n",ans);
    return 0;
}
