N=io.read("*n", "*l")
S=io.read()

T={}
for i=1,N do
    if T[S:sub(i,i)] == nil then
        T[S:sub(i,i)] = 1
    else
        T[S:sub(i,i)] = T[S:sub(i,i)] + 1
    end
end

M=T["R"]*T["G"]*T["B"]

for i=1,N do
    x=S:sub(i,i)
    for j=1,N do
        y=S:sub(i+j,i+j)
        z=S:sub(i+2*j,i+2*j)
        if x~=y and y~=z and z~=x then
            M = M-1
        end
    end
end

print(M)