import java.util.Scanner
import java.lang.Math.*

fun main(args: Array<String>) {
	val scn = Scanner(System.`in`)
	val n = scn.nextInt()
	val s = scn.next()
	val arr = Array(3){ mutableListOf<Int>() }
	s.forEachIndexed{i, c ->
		val t = when(c){'R'->0 'G'->1 else->2}
		arr[t].add(i)
	}
	arr.sortBy{it.size}
	var ans = 0L
	arr[0].forEach { r ->
		arr[1].forEach { g ->
			val b1 = min(r, g) - abs(r-g)
			val b2 = max(r, g) + abs(r-g)
			val b3 = if((r-g)%2==0) (r+g)/2 else -1
			var bcnt = arr[2].size
			if (arr[2].binarySearch(b1)>=0) bcnt--
			if (arr[2].binarySearch(b2)>=0) bcnt--
			if (arr[2].binarySearch(b3)>=0) bcnt--
			ans+=bcnt
		}
	}
	println(ans)
}