N = int(eval(input()))

S = eval(input())



bad_list = ['RGB', 'RBG', 'GRB', 'GBR', 'BRG', 'BGR']

res = S.count("R") * S.count("G") * S.count("B")

for (i, s) in enumerate(S):

  

  for j in range(((i+1)//2)+1)[1:]:

    if S[i::-j][:3] in bad_list:

      res -= 1





print(res)
N = int(eval(input()))

S = eval(input())



res = S.count("R") * S.count("G") * S.count("B")

for i in range(N):

  for j in range(N)[i:]:

    k = 2*j-i

    if N <= k:

      break

    if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:

      res -= 1



print(res)
N = int(eval(input()))
S = eval(input())
bad_list = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"]
res = S.count("R") * S.count("G") * S.count("B")
for (i, s) in enumerate(S):
    for j in range(((i + 1) // 2) + 1)[1:]:
        if S[i::-j][:3] in bad_list:
            res -= 1
print(res)

N = int(eval(input()))
S = eval(input())
res = S.count("R") * S.count("G") * S.count("B")
for i in range(N):
    for j in range(N)[i:]:
        k = 2 * j - i
        if N <= k:
            break
        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
            res -= 1
print(res)

-bad_list = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"] -for (i, s) in enumerate(S): -    for j in range(((i + 1) // 2) + 1)[1:]: -        if S[i::-j][:3] in bad_list: +for i in range(N): +    for j in range(N)[i:]: +        k = 2 * j - i +        if N <= k: +            break +        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]: