N = int(input())
S = input()

R,G,B = 0,0,0

for i in range(0,N):
    char = S[i]
    if char == "R":
        R += 1
    elif char == "G":
        G += 1
    elif char == "B":
        B += 1

count = R * G * B

N2 = int(N/2 + 0.5)
for i in range(0,N):
    stri = S[i]
    for j in range(0, N2):
        j2 = 2 * j
        if i+j2 >= N:
            break
        strj = S[i+j]
        strk = S[i+j2]
        if stri != strj and strj != strk and stri != strk:
            count -= 1
print(count)