#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

signed main(void)
{
	int n, cnt, sum;
	string s;
	map<char, int> mp;

	cin >> n >> s;
	sum = 1;
	rep(i, n) mp[s[i]]++;
	for(auto p : mp)
	{
		sum *= p.second; 
	}
	cnt = 0;
	rep(i, n)
	{
		for(int j = i + 1; j < n; j++)
		{
			int k = 2 * j - i;
			if (k >= n) continue;
			if (s[i] != s[j] && s[j] != s[k] && s[i] != s[k])
				cnt++;
		}
	}
	cout << sum - cnt << endl;
	return 0;
}
