import std;

void main()
{
    const N = readln().chomp().to!size_t();
    const S = readln().chomp();

    size_t count = 0;

    foreach (size_t i; 0 .. N)
    foreach (size_t j; i + 1 .. N)
    foreach (size_t k; j + 1 .. N)
    {
        if (S[i] == S[j]) continue;
        if (S[i] == S[k]) continue;
        if (S[j] == S[k]) continue;
        if (j - i == k - j) continue;
        count++;
    }

    writeln(count);
}
