'use strict';

function Main(input) {
    const tmp = input.trim().split('\n');
    const N = Number(tmp[0]);
    const S = tmp[1];
    // console.log(N, S);

    let result = 0;
    for (let head = 0; head < N - 3; head++) {
        for (let tail = 3; tail < N; tail++) {
            for (let center = head + 1; center < tail; center++) {
                if (center - head === tail - center) continue;
                const checkArr = [S[head], S[center], S[tail]];
                if (check(checkArr)) {
                    result++;
                }
            }
        }
    }
    console.log(result);

}
function check(arr) {
    if (arr[0] !== arr[1] && arr[0] !== arr[2] && arr[1] !== arr[2]) {
        return true;
    }
    return false;
}

Main(require('fs').readFileSync('/dev/stdin', 'utf8'));

// Main(`4
// RRGB`);
// Main(`39
// RBRBGRBGGBBRRGBBRRRBGGBRBGBRBGBRBBBGBBB`);
