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

int n;
string s;

int main() {
  	ios_base::sync_with_stdio(false);
  	cin.tie(nullptr);
  
	cin >> n >> s;

	s.insert(0, "#");

	long long ans = 0LL;
	
	for (int i = 1; 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[j] != s[k] && s[i] != s[k] && (j - i != k - j)) {
					++ans;
				}
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}
