#include <iostream>
#include <vector>
#include<string>

using namespace std;

int main() {
	int N;
	string S;
	cin >> N >> S;
	int count = 0;
	for (int i = 0; i < N-2; i++) {
		for (int j = i+1; j < N-1 ; j++) {
			if (S.at(i) != S.at(j)) {
				string part = S.substr(2 * j - i + 1);
				for (int k = 1; k < (N - 2 * j + i - 1); k++) {
					if (S.at(i) != S.at(j) && S.at(i) != S.at(k) && S.at(k) != S.at(j)) {
						count++
					}
				}
			}
		}
	}
	cout << count << endl;
}