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

r, g, b = 0, 0, 0
for c in S:
  if c == "R": r += 1
  if c == "G": g += 1
  if c == "B": b += 1

total = r*g*b

for i in range(len(S)):
  for j in range(i+1, len(S)):
    if S[i] == S[j]: continue

    k = 2*j - i
    if k >= N: continue
    if len(set((S[i], S[k], S[j]))) == 3:
      total -= 1

print(total)