fun main() {
    val N = readLine()!!.toInt()
    val S = readLine()!!

    val R = IntArray(N)
    val G = IntArray(N)
    val B = IntArray(N)

    when (S[0]) {
        'R' -> {
            R[0] = 1
        }
        'G' -> {
            G[0] = 1
        }
        'B' -> {
            B[0] = 1
        }
    }
    for (i in 1..S.lastIndex) {
        val c = S[i]
        when (c) {
            'R' -> {
                R[i] = R[i - 1] + 1
                G[i] = G[i - 1]
                B[i] = B[i - 1]
            }
            'G' -> {
                R[i] = R[i - 1]
                G[i] = G[i - 1] + 1
                B[i] = B[i - 1]
            }
            'B' -> {
                R[i] = R[i - 1]
                G[i] = G[i - 1]
                B[i] = B[i - 1] + 1
            }
        }
    }

    var sum = 0L
    for (i in 0..S.lastIndex - 2) {
        for (j in i + 1..S.lastIndex - 1) {
            if (S[i] == S[j]) {
                continue
            }
            val a = arrayOf(S[i], S[j])
            sum += when {
                !a.contains('R') -> {
                    var n = R[S.lastIndex] - R[j]
                    if ((j + (j - i)) <= S.lastIndex && S[j + (j - i)] == 'R') {
                        n--
                    }
                    n
                }
                !a.contains('G') -> {
                    var n = G[S.lastIndex] - G[j]
                    if ((j + (j - i)) <= S.lastIndex && S[j + (j - i)] == 'G') {
                        n--
                    }
                    n
                }
                !a.contains('B') -> {
                    var n = B[S.lastIndex] - B[j]
                    if ((j + (j - i)) <= S.lastIndex && S[j + (j - i)] == 'B') {
                        n--
                    }
                    n
                }
                else -> throw IllegalStateException("")
            }


        }
    }
    println(sum)
}

