#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  int   scan; // scanf result
  ull   answer; // to output 
  int   n; // to input 
  char *s;

  scan = scanf("%d", &n);
  s = (char *)malloc(sizeof(char) * (n + 1));
  scan = scanf("%s", s);
  answer = 0;

  int i = 0;
  int j = 0;
  int k = 0;
  while (i < n) {
    j = i + 1;
    while (j < n) {
      k = j + 1;
      while (k < n) {
        if (s[i] != s[j] && s[i] != s[k] && s[j] != s[k]) {
          if ((j - i) != (k - j)) {
            answer += 1;
          }
        }
        k++;
      }
      j++;
    }
    i++;
  }

  printf("%llu", answer);
  return (0);
}
