#include <iostream>
using namespace std;

int main(){
    int n;
    string s;
    cin >> n >> s;
    int i, j, k, Ans = 0;
    for(i=0;i<n-2;i++){
        char I = s[i];
        for(j=i+1;j<n-1;j++){
            char J = s[j];
            if(J == I){
                continue;
            }
            for(k=j+1;k<n;k++){
                char K = s[k];
                if(K == I || K == J || (j-i == k-j)){
                    continue;
                }
                Ans++;
            }
        }
    }

    cout << Ans << endl;
    return 0;
}