#include <iostream>
#include <string>

// data structure
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <vector>

#include <algorithm>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[]) {
  int n;
  string s;
  cin >> n;
  cin >> s;

  int count = 0;
  for (int k = 3; k < n; k++) {
    for (int j = 1; j < k; j++) {
      for (int i = 0; i < j; i++) {
        if (j - i == k - j)
          continue;
        if (s.at(i) != s.at(j) && s.at(i) != s.at(k) && s.at(j) != s.at(k))
          count++;
      }
    }
  }

  std::cout << count << std::endl;

  return 0;
}
