N = int(input())
S = input()

# 全探索
cnt = 0
for i in range(0, N-2):
  for j in range(i+1, N-1):
    for k in range(j+1, N):
      # 条件1(全要素が異なる文字判定)
      if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
        # 条件2判定
        if j - i != k - j:
          cnt += 1

print(cnt)