n = int(input())
s = input()
cnt = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i] != s[j]:
            if 2*j-i <= n-1:
                if s[2*j-i] not in(s[i],s[j]):
                    cnt -= 1
print(cnt)