from sys import stdin

import bisect

def main():

    #入力

    readline=stdin.readline

    N=int(readline())

    S=readline().strip()



    res=0



    R=[]

    G=[]

    B=[]

    flags=[""]*N

    for i in range(N):

        if S[i]=="R":

            R.append(i)

            flags[i]="R"

        elif S[i]=="G":

            G.append(i)

            flags[i]="G"

        else:

            B.append(i)

            flags[i]="B"

    

    #Bが最後

    for i in range(len(R)):

        for j in range(len(G)):

            n=max(R[i],G[j])

            k=bisect.bisect_left(B,n)

            res+=len(B)-k

            if n+n-min(R[i],G[j])<N:

                if flags[n+n-min(R[i],G[j])]=="B":

                    res-=1

    

    for i in range(len(R)):

        for j in range(len(B)):

            n=max(R[i],B[j])

            k=bisect.bisect_left(G,n)

            res+=len(G)-k

            if n+n-min(R[i],B[j])<N:

                if flags[n+n-min(R[i],B[j])]=="G":

                    res-=1



    for i in range(len(B)):

        for j in range(len(G)):

            n=max(B[i],G[j])

            k=bisect.bisect_left(R,n)

            res+=len(R)-k

            if n+n-min(B[i],G[j])<N:

                if flags[n+n-min(B[i],G[j])]=="R":

                    res-=1



    print(res)

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 bisect


def main():
    # 入力
    readline = stdin.readline
    N = int(readline())
    S = readline().strip()
    res = 0
    R = []
    G = []
    B = []
    flags = [""] * N
    for i in range(N):
        if S[i] == "R":
            R.append(i)
            flags[i] = "R"
        elif S[i] == "G":
            G.append(i)
            flags[i] = "G"
        else:
            B.append(i)
            flags[i] = "B"
    # Bが最後
    for i in range(len(R)):
        for j in range(len(G)):
            n = max(R[i], G[j])
            k = bisect.bisect_left(B, n)
            res += len(B) - k
            if n + n - min(R[i], G[j]) < N:
                if flags[n + n - min(R[i], G[j])] == "B":
                    res -= 1
    for i in range(len(R)):
        for j in range(len(B)):
            n = max(R[i], B[j])
            k = bisect.bisect_left(G, n)
            res += len(G) - k
            if n + n - min(R[i], B[j]) < N:
                if flags[n + n - min(R[i], B[j])] == "G":
                    res -= 1
    for i in range(len(B)):
        for j in range(len(G)):
            n = max(B[i], G[j])
            k = bisect.bisect_left(R, n)
            res += len(R) - k
            if n + n - min(B[i], G[j]) < N:
                if flags[n + n - min(B[i], G[j])] == "R":
                    res -= 1
    print(res)


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()

-import bisect -    N = int(readline()) -    S = readline().strip() -    res = 0 -    R = [] -    G = [] -    B = [] -    flags = [""] * N -    for i in range(N): -        if S[i] == "R": -            R.append(i) -            flags[i] = "R" -        elif S[i] == "G": -            G.append(i) -            flags[i] = "G" -        else: -            B.append(i) -            flags[i] = "B" -    # Bが最後 -    for i in range(len(R)): -        for j in range(len(G)): -            n = max(R[i], G[j]) -            k = bisect.bisect_left(B, n) -            res += len(B) - k -            if n + n - min(R[i], G[j]) < N: -                if flags[n + n - min(R[i], G[j])] == "B": -                    res -= 1 -    for i in range(len(R)): -        for j in range(len(B)): -            n = max(R[i], B[j]) -            k = bisect.bisect_left(G, n) -            res += len(G) - k -            if n + n - min(R[i], B[j]) < N: -                if flags[n + n - min(R[i], B[j])] == "G": -                    res -= 1 -    for i in range(len(B)): -        for j in range(len(G)): -            n = max(B[i], G[j]) -            k = bisect.bisect_left(R, n) -            res += len(R) - k -            if n + n - min(B[i], G[j]) < N: -                if flags[n + n - min(B[i], G[j])] == "R": -                    res -= 1 -    print(res) +    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)