function main(input) {
  const inputs = input.split('\n')
  const N = Number(inputs[0])
  const S = inputs[1]

  // 貪欲

  let count = 0
  for(let i = 0; i < N - 2; i++) {
    for(let j = i + 1; j < N - 1; j++) {
      if (S[i] === S[j]) continue
      const ji = j - i
      for (let k = j + 1; k < N; k++) {
        if (S[j] === S[k]) continue
        if (k - j === ji) continue
        if (S[i] === S[k]) continue
        count++
      }
    }
  }
  console.log(count)
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));
