#include <bits/stdc++.h>
using namespace std;

int main() {
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/
	int n, ans = 0;
	string s;
	cin >> n >> s;

	for (int i=0; i<n; i++) {
		for (int j=i+1; j<n; j++) {
			for (int k=j+1; k<n; k++) {
				if (s[i]!=s[j] && s[i]!=s[k] && s[j]!=s[k])
					if (j-i != k-j) ++ans;
			}
		}
	}

	cout << ans << '\n';
	return 0;
}