"use strict";

const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const S = arg[1];
    
    const index = [];
    let answer = 0;
    
    for(let i=0; i<N-2; i++) {
        for(let j=i+1; j<N-1; j++) {
            if(S[i] === S[j]) {
                continue;
            }
            
            for(let k=j+1; k<N; k++) {
                if(S[i] === S[j] || S[j] === S[k] || S[i] === S[k]) {
                    continue;
                }

                if(j - i === k - j) {
                    continue;
                }
                
                answer++;
            }
        }
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));