#include <bits/stdc++.h>

using namespace std;

int main(){

int n;
cin>>n;

vector<char>s(n);

for(int i = 0 ;i < n;i++){
	cin >> s[i];
}

int count = 0;
for(int a = 0;a < n-2;a++){
	for(int b = a+1;b< n-1;b++){
	for(int c = b+1;a < n;c++){
	if((a+c)/2!=b&&(a+c)%2!=0&&s[a] != s[b]&&s[a] != s[c] &&s[b] == s[c]){
		count++;
	}
	}
	}
}

cout << count <<endl;
}