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

int main(void) {
    int N;
    cin >> N;
    string S;
    cin >> S;
    if (N < 3) {
        printf("0\n");
        return 0;
    }
    int same = 0;
    for (int l = 3; l <= N; l += 2) {
        same += (N - l + 1);
    }
    int sameS = 0, sameSsame = 0;
    for (int i = 0; i < N - 2; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            for (int k = j + 1; k < N; k++) {
                if (S[i] == S[k] || S[i] == S[j] || S[j] == S[k]) {
                    ++sameS;
                    if (j - i == k - j) {
                        ++sameSsame;
                    }
                }
            }
        }
    }
    int ans = N * (N - 1) * (N - 2) / 6;
    ans = ans - same - sameS + sameSsame;
    printf("%d\n", ans);
    return 0;
}
