def solution():

    n = int(eval(input()))

    s = eval(input())



    ans = s.count('R') * s.count('G') * s.count('B')

    for i in range(n):

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

            k = (j - i) + j

            if k < 1 or k >= n:

                continue

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

                ans -= 1

    print(ans)



solution()

def solution():

    n = int(eval(input()))

    s = eval(input())



    ans = s.count('R') * s.count('G') * s.count('B')

    for i in range(n):

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

            k = (j - i) + j

            if k >= n:

                break

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

                ans -= 1

    print(ans)



solution()

def solution():
    n = int(eval(input()))
    s = eval(input())
    ans = s.count("R") * s.count("G") * s.count("B")
    for i in range(n):
        for j in range(i + 1, n + 1):
            k = (j - i) + j
            if k < 1 or k >= n:
                continue
            if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
                ans -= 1
    print(ans)


solution()

def solution():
    n = int(eval(input()))
    s = eval(input())
    ans = s.count("R") * s.count("G") * s.count("B")
    for i in range(n):
        for j in range(i + 1, n + 1):
            k = (j - i) + j
            if k >= n:
                break
            if s[i] != s[j] and s[j] != s[k] and s[i] != s[k]:
                ans -= 1
    print(ans)


solution()

-            if k < 1 or k >= n: -                continue +            if k >= n: +                break