n = int(input())
s = list(input())
counter = 0
for i in range(n - 2):
  for j in range(i + 1, n - 1):
    for k in range(j + 1, n):
      if ((j - i) != (k - j)):
        if (s[i] != s[j]) & (s[j] != s[k]) & (s[k] != s[i]):
          counter += 1
print(counter)