import bisect

N = int(eval(input()))

S = eval(input())

R=[]

G=[]

B=[]

ans=0

for i, s in enumerate(S):

    if s == "R":

        R.append(i)

    elif s == "G":

        G.append(i)

    else:

        B.append(i)

blen=len(B)

for ri in range(len(R)):

    for gi in range(len(G)):

        x, y = sorted([R[ri], G[gi]])

        ans+=blen

        bi = bisect.bisect_left(B,2*y-x)

        if bi < blen and B[bi] == 2*y-x:

            ans -= 1

        bi = bisect.bisect_left(B,(x+y)/2)

        if bi < blen and B[bi] == (x+y)/2:

            ans -= 1

        bi = bisect.bisect_left(B, 2 * x - y)

        if bi < blen and B[bi] == 2 * x - y:

            ans -= 1

print(ans)



        

        



        

N = int(eval(input()))

S = eval(input())

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

for i in range(len(S)):

    for j in range(i + 1, len(S)):

        k = j * 2 - i

        if k >= len(S):

            break

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

            ans -= 1

print(ans)
import bisect

N = int(eval(input()))
S = eval(input())
R = []
G = []
B = []
ans = 0
for i, s in enumerate(S):
    if s == "R":
        R.append(i)
    elif s == "G":
        G.append(i)
    else:
        B.append(i)
blen = len(B)
for ri in range(len(R)):
    for gi in range(len(G)):
        x, y = sorted([R[ri], G[gi]])
        ans += blen
        bi = bisect.bisect_left(B, 2 * y - x)
        if bi < blen and B[bi] == 2 * y - x:
            ans -= 1
        bi = bisect.bisect_left(B, (x + y) / 2)
        if bi < blen and B[bi] == (x + y) / 2:
            ans -= 1
        bi = bisect.bisect_left(B, 2 * x - y)
        if bi < blen and B[bi] == 2 * x - y:
            ans -= 1
print(ans)

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

-import bisect - -R = [] -G = [] -B = [] -ans = 0 -for i, s in enumerate(S): -    if s == "R": -        R.append(i) -    elif s == "G": -        G.append(i) -    else: -        B.append(i) -blen = len(B) -for ri in range(len(R)): -    for gi in range(len(G)): -        x, y = sorted([R[ri], G[gi]]) -        ans += blen -        bi = bisect.bisect_left(B, 2 * y - x) -        if bi < blen and B[bi] == 2 * y - x: -            ans -= 1 -        bi = bisect.bisect_left(B, (x + y) / 2) -        if bi < blen and B[bi] == (x + y) / 2: -            ans -= 1 -        bi = bisect.bisect_left(B, 2 * x - y) -        if bi < blen and B[bi] == 2 * x - y: +ans = S.count("R") * S.count("B") * S.count("G") +for i in range(len(S)): +    for j in range(i + 1, len(S)): +        k = j * 2 - i +        if k >= len(S): +            break +        if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]: