n=int(eval(input()));s=eval(input());c=s.count;print((c('R')*c('G')*c('B')-sum(sorted(s[i:j+1:(j-i)//2])==list('BGR')for i in range(n-2)for j in range(i+2,n,2))))
n=int(eval(input()));s=eval(input());c=s.count;print((c('R')*c('G')*c('B')-sum(len(set(s[i:j+1:(j-i)//2]))>2for i in range(n-2)for j in range(i+2,n,2))))
n = int(eval(input()))
s = eval(input())
c = s.count
print(
    (
        c("R") * c("G") * c("B")
        - sum(
            sorted(s[i : j + 1 : (j - i) // 2]) == list("BGR")
            for i in range(n - 2)
            for j in range(i + 2, n, 2)
        )
    )
)

n = int(eval(input()))
s = eval(input())
c = s.count
print(
    (
        c("R") * c("G") * c("B")
        - sum(
            len(set(s[i : j + 1 : (j - i) // 2])) > 2
            for i in range(n - 2)
            for j in range(i + 2, n, 2)
        )
    )
)

-            sorted(s[i : j + 1 : (j - i) // 2]) == list("BGR") +            len(set(s[i : j + 1 : (j - i) // 2])) > 2