object Main extends App {
	val N = scala.io.StdIn.readInt
	val S = scala.io.StdIn.readLine.toList.toArray

	var r = 0
	var g = 0
	var b = 0

	for(x <- S){
		x match {
			case 'R' => r += 1
			case 'G' => g += 1
			case 'B' => b += 1 
		}
	}

	var ans = r*g*b.toLong

	for(i<-0 until N){
		for(j<-i+1 until N){
			val k = 2*j - i
			if(k < N){
				if(S(i) != S(j) && S(j) != S(k) && S(i) != S(k)) ans -= 1
			}
		}
	}

//	println("r:" + r + " g:" + g + " b:" + b)

	println(ans)

}