"use strict";

// 最大公約数その2（多入力対応）
const getGcd = array => {
  let len, a, b;
	
  len = array.length;
	a   = array[0];
	
  for (let i=1; i<len; i++) {
		b = array[i];
		a = gcdTwoNumbers(a, b);
	}

	return a;
}

function gcdTwoNumbers(x, y) {
  x = Math.abs(x);
  y = Math.abs(y);
  while(y) {
    let t = y;
    y = x % y;
    x = t;
  }
  return x;
}

//　組み合わせ 被りなし
const combineWithoutRepetitions = (comboOptions, comboLength) => {
  if (comboLength === 1) {
    return comboOptions.map(comboOption => [comboOption]);
  }

  // Init combinations array.
  const combos = [];

  // Eliminate characters one by one and concatenate them to
  // combinations of smaller lengths.
  comboOptions.forEach((currentOption, optionIndex) => {
    const smallerCombos = combineWithoutRepetitions(
      comboOptions.slice(optionIndex + 1),
      comboLength - 1
    );

    smallerCombos.forEach((smallerCombo) => {
      combos.push([currentOption].concat(smallerCombo));
    });
  });

  return combos;
}

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; i++) {
        index.push(i);
    }
    
    const combos = combineWithoutRepetitions(index, 3);
    const combosLength = combos.length;
    
    // console.log(combos);
    
    for(let c=0; c<combosLength; c++) {
        let i = combos[c][0];
        let j = combos[c][1];
        let k = combos[c][2];
        
        // console.log("combos[c]:" + combos[c] )
        
        // console.log("i:" + i)
        // console.log("j:" + j)
        // console.log("k:" + k)
        
        // console.log("S[i]:" + S[i])
        // console.log("S[j]:" + S[j])
        // console.log("S[k]:" + S[k])
        
        if(S[i] === S[j]) {
            continue;
        }
        
        if(S[j] === S[k]) {
            continue;
        }
        
        if(S[i] === S[k]) {
            continue;
        }
        
        // console.log("j-i:" + (j-i))
        // console.log("k-j:" + (k-j))
        
        if(j - i === k - j) {
            continue;
        }
        
        // console.log("条件を満たす")
        // console.log("---")
        
        answer++;
    }
    
    console.log(answer);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));