n = int(eval(input()))

s = list(eval(input()))



r = s.count('R')

g = s.count('G')

b = s.count('B')



cnt = 0

for i in range(n):

    for j in range(i+1,n):

        k = j*2-i

        if k >= n:

            break

        elif s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:

            cnt +=1

print((r*g*b - cnt))
def solve2():

    n = int(eval(input()))

    s = list(eval(input()))



    r = s.count('R')

    g = s.count('G')

    b = s.count('B')



    cnt = 0

    for i in range(n):

        for j in range(i+1,n):

            k = j*2-i

            if k >= n:

                break

            elif s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:

                cnt +=1

    return r*g*b - cnt



print((solve2()))
n = int(eval(input()))
s = list(eval(input()))
r = s.count("R")
g = s.count("G")
b = s.count("B")
cnt = 0
for i in range(n):
    for j in range(i + 1, n):
        k = j * 2 - i
        if k >= n:
            break
        elif s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            cnt += 1
print((r * g * b - cnt))

def solve2():
    n = int(eval(input()))
    s = list(eval(input()))
    r = s.count("R")
    g = s.count("G")
    b = s.count("B")
    cnt = 0
    for i in range(n):
        for j in range(i + 1, n):
            k = j * 2 - i
            if k >= n:
                break
            elif s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                cnt += 1
    return r * g * b - cnt


print((solve2()))

-n = int(eval(input())) -s = list(eval(input())) -r = s.count("R") -g = s.count("G") -b = s.count("B") -cnt = 0 -for i in range(n): -    for j in range(i + 1, n): -        k = j * 2 - i -        if k >= n: -            break -        elif s[i] != s[j] and s[j] != s[k] and s[k] != s[i]: -            cnt += 1 -print((r * g * b - cnt)) +def solve2(): +    n = int(eval(input())) +    s = list(eval(input())) +    r = s.count("R") +    g = s.count("G") +    b = s.count("B") +    cnt = 0 +    for i in range(n): +        for j in range(i + 1, n): +            k = j * 2 - i +            if k >= n: +                break +            elif s[i] != s[j] and s[j] != s[k] and s[k] != s[i]: +                cnt += 1 +    return r * g * b - cnt + + +print((solve2()))