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

int main() {
  int N;
  string S;
  cin >> N >> S;
  int64_t sum = 0;
  for (int i = 0; i < N; i++) {
    char tmp1 = S.at(i);
      for (int j = i + 1; j < N; j++) {
        if (S.at(j) != tmp1) {
          char tmp2 = S.at(j);
          for (int k = j + 1; k < N; k++) {
            if (S.at(k) != tmp1 && S.at(k) != tmp2 && j - i != k - j) {
              sum++;
            }
          }
        }
      }
  }
  cout << sum << endl;
}
