from sys import stdin

def main():

    #入力

    readline=stdin.readline

    n=int(readline())

    s=readline().strip()

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



    for i in range(n):

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

            k=2*j-i

            if k>=n: break

            x=s[i]

            y=s[j]

            z=s[k]

            if x!=y and y!=z and z!=x:

                ans-=1



    print(ans)



if __name__=="__main__":

    main()
from sys import stdin

import numpy as np

def main():

    #入力

    readline=stdin.readline

    n=int(readline())

    s=readline().strip()

    t=np.array([1 if s[i]=="R" else 2 if s[i]=="G" else 3 for i in range(n)],dtype=np.int64)

    ans=t[t==1].size*t[t==2].size*t[t==3].size



    for i in range(n):

        if (n+i)%2==0:

            j=np.arange(i+1,(n+i)//2)

            k=2*j-i

        else:

            j=np.arange(i+1,(n+i)//2+1)

            k=2*j-i



        if j.size==0:

            break

        i=np.full(j.size,i,dtype=np.int64)

        tmp=t[i]*t[j]*t[k]

        ans-=tmp[tmp==6].size



    print(ans)



if __name__=="__main__":

    main()
from sys import stdin


def main():
    # 入力
    readline = stdin.readline
    n = int(readline())
    s = readline().strip()
    ans = s.count("R") * s.count("G") * s.count("B")
    for i in range(n):
        for j in range(i + 1, n):
            k = 2 * j - i
            if k >= n:
                break
            x = s[i]
            y = s[j]
            z = s[k]
            if x != y and y != z and z != x:
                ans -= 1
    print(ans)


if __name__ == "__main__":
    main()

from sys import stdin
import numpy as np


def main():
    # 入力
    readline = stdin.readline
    n = int(readline())
    s = readline().strip()
    t = np.array(
        [1 if s[i] == "R" else 2 if s[i] == "G" else 3 for i in range(n)],
        dtype=np.int64,
    )
    ans = t[t == 1].size * t[t == 2].size * t[t == 3].size
    for i in range(n):
        if (n + i) % 2 == 0:
            j = np.arange(i + 1, (n + i) // 2)
            k = 2 * j - i
        else:
            j = np.arange(i + 1, (n + i) // 2 + 1)
            k = 2 * j - i
        if j.size == 0:
            break
        i = np.full(j.size, i, dtype=np.int64)
        tmp = t[i] * t[j] * t[k]
        ans -= tmp[tmp == 6].size
    print(ans)


if __name__ == "__main__":
    main()

+import numpy as np -    ans = s.count("R") * s.count("G") * s.count("B") +    t = np.array( +        [1 if s[i] == "R" else 2 if s[i] == "G" else 3 for i in range(n)], +        dtype=np.int64, +    ) +    ans = t[t == 1].size * t[t == 2].size * t[t == 3].size -        for j in range(i + 1, n): +        if (n + i) % 2 == 0: +            j = np.arange(i + 1, (n + i) // 2) -            if k >= n: -                break -            x = s[i] -            y = s[j] -            z = s[k] -            if x != y and y != z and z != x: -                ans -= 1 +        else: +            j = np.arange(i + 1, (n + i) // 2 + 1) +            k = 2 * j - i +        if j.size == 0: +            break +        i = np.full(j.size, i, dtype=np.int64) +        tmp = t[i] * t[j] * t[k] +        ans -= tmp[tmp == 6].size