import "dart:io";

void main(List<String> args) {
  int n = int.parse(stdin.readLineSync());
  String s = stdin.readLineSync();
  int count = 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[j]) k = n;
        if (isValid1(s, i, j, k) && isValid2(i, j, k)) count++;
      }
    }
  }

  print(count);
}

bool isValid1(String s, int i, int j, int k) {
  return s[i] != s[j] && s[i] != s[k] && s[j] != s[k];
}

bool isValid2(int i, int j, int k) {
  return j - i != k - j;
}