fun main() {
    val n = readLine()!!.toInt()
    val s = readLine()!!

    val dp = LongArray(8)
    dp[0] = 1

    s.forEach {
        when (it) {
            'R' -> {
                dp[7] += dp[3]
                dp[6] += dp[2]
                dp[5] += dp[1]
                dp[4] += dp[0]
            }
            'G' -> {
                dp[7] += dp[5]
                dp[6] += dp[4]
                dp[3] += dp[1]
                dp[2] += dp[0]
            }
            'B' -> {
                dp[7] += dp[6]
                dp[5] += dp[4]
                dp[3] += dp[2]
                dp[1] += dp[0]
            }
        }
    }

    val exclude = (0..n-3).sumBy { l ->
        (1..n).count { w ->
            val c = l + w
            val r = c + w
            r < n && s[l] != s[c] && s[c] != s[r] && s[r] != s[l]
        }
    }

    println(dp[7]-exclude)
}