N = int(input())
S = input()
## [color][idx]
RGB = [[0 for i in range(N)] for j in "RGB"]
for idx,ch in enumerate(S):
  for color_idx in [0,1,2]:
    RGB[color_idx][idx] = RGB[color_idx][idx-1]
  RGB["RGB".index(ch)][idx] += 1
ans = 0
for i in range(N-2):
  for j in range(i+1,N-1):
    if S[i] != S[j]:
      nokori = {"R","G","B"} - {S[i],S[j]}
      n_ch = [ch for ch in nokori][0]
      n_idx = "RGB".index(n_ch)
      ans += RGB[n_idx][-1]-RGB[n_idx][j]-(1 if (j+(j-i)<N and  S[j + (j-i)] == n_ch) else 0)
print (ans)