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

rn = [0]*(N+1)
gn = [0]*(N+1)
bn = [0]*(N+1)

for i in range(N):
    rn[i+1] = rn[i]
    gn[i+1] = gn[i]
    bn[i+1] = bn[i]
    if S[i]=="R":
        rn[i+1] = rn[i]+1
    if S[i]=="G":
        gn[i+1] = gn[i]+1
    if S[i]=="B":
        bn[i+1] = bn[i]+1
   
ans = 0
for i in range(N):
    a = S[i]
    rem = "RGB".replace(a,"")
    for j in range(N-i):
        if (S[j+i] == a):
            continue
        b = S[j+i]
        rem2 = rem.replace(b,"")
        if rem2 == "R":
            ans += rn[N]-rn[j+i+1]
        if rem2 == "G":
            ans += gn[N]-gn[j+i+1]
        if rem2 == "B":
            ans += bn[N]-bn[j+i+1]
        if 0 <= j*2+i <= N-1:
          if S[j*2+i] == rem2 :
              ans -=1
            
print(ans)