from collections import defaultdict
n = int(input())
s = input()
d = defaultdict(int)
for c in s:
  d[c] += 1
ans = d['R'] * d['G'] * d['B']
for i in range(1, n):
  for j in range(n-2*i):
    if s[j] != s[j+i] and s[j+i] != s[j+2*i] and s[j+2*i] != s[j]:
      ans -= 1
print(ans)