n = int(input())
s = input()

ans = s.count("R") * s.count("G") * s.count("B")

for i in range(n-2):
    si = s[i]
    for j in range(i+1, i+(n-i-1)//2+1):
        sj = s[j]
        k = 2*j-i
        if k < n and s[k] != si and s[k] != sj and si != sj:
            ans -= 1

print(ans)