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

typedef long long ll;

int main()
{
    int N;
    string S;
    cin >> N >> S;
    int size = S.size();
    ll ans = 0;
    for (int i = 0; i < size - 2; ++i)
    {
        for (int j = i + 1; j < size - 1; ++j)
        {
            for (int k = j + 1; k < size; ++k)
            {
                if (S[i] != S[j] && S[i] != S[k] && S[j] != S[k])
                {
                    if (j - i != k - j)
                    {
                        ++ans;
                    }
                }
            }
        }
    }
    cout << ans << endl;
}
