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

R = 0
G = 0
B = 0

# R,G,Bの数を数える
for i in range(N):
    if S[i] == 'R':
        R += 1
    elif S[i] == 'G':
        G += 1
    else:
        B += 1
    
# 等間隔で(R,G,B)の組み合わせとなっている数を数える
# 間隔(step)は1～1999のいずれか
count = 0
for step in range(1,2000):
    start = 0
    while (start + step * 2) < N:
        i,j,k = start, start+step, start+step*2
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            count += 1
        start += 1

# print(count)

print(R*G*B - count)