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

int main(){
    int n;
    string s;
    int ans = 0;
    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[j]!=s[k] && s[k] != s[i] && j-i != k-j){
                    ans++;
                }
            }
        }
    }
    cout << ans;
}