N = int(eval(input()))

S = eval(input())

R, G, B = [],[],[]

for i,s in enumerate(S):

    if s=='R':

        R.append(i)

    elif s=='G':

        G.append(i)

    else:

        B.append(i)



R.sort()

G.sort()

B.sort()



from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort

 

ans = len(R)*len(G)*len(B)

if ans > 0:

    for r in R:

        for g in G:

            for p in [r*2-g,g*2-r,(r+g)/2]:

                if p<=B[-1] and p>=B[0]:

                    ind = bisect_left(B,p)

                    if p == B[ind]:

                        ans -= 1



print(ans)



from collections import Counter

def solve():

  N = int(eval(input()))

  S = list(eval(input()))

  c = Counter(S)

  ans = c['R']*c['G']*c['B']

  for i in range(N):

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

      k = j*2-i

      if k>N-1:

        break

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

        ans -= 1

  return ans

print((solve()))
N = int(eval(input()))
S = eval(input())
R, G, B = [], [], []
for i, s in enumerate(S):
    if s == "R":
        R.append(i)
    elif s == "G":
        G.append(i)
    else:
        B.append(i)
R.sort()
G.sort()
B.sort()
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort

ans = len(R) * len(G) * len(B)
if ans > 0:
    for r in R:
        for g in G:
            for p in [r * 2 - g, g * 2 - r, (r + g) / 2]:
                if p <= B[-1] and p >= B[0]:
                    ind = bisect_left(B, p)
                    if p == B[ind]:
                        ans -= 1
print(ans)

from collections import Counter


def solve():
    N = int(eval(input()))
    S = list(eval(input()))
    c = Counter(S)
    ans = c["R"] * c["G"] * c["B"]
    for i in range(N):
        for j in range(i + 1, N):
            k = j * 2 - i
            if k > N - 1:
                break
            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]:
                ans -= 1
    return ans


print((solve()))

-N = int(eval(input())) -S = eval(input()) -R, G, B = [], [], [] -for i, s in enumerate(S): -    if s == "R": -        R.append(i) -    elif s == "G": -        G.append(i) -    else: -        B.append(i) -R.sort() -G.sort() -B.sort() -from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort +from collections import Counter -ans = len(R) * len(G) * len(B) -if ans > 0: -    for r in R: -        for g in G: -            for p in [r * 2 - g, g * 2 - r, (r + g) / 2]: -                if p <= B[-1] and p >= B[0]: -                    ind = bisect_left(B, p) -                    if p == B[ind]: -                        ans -= 1 -print(ans) + +def solve(): +    N = int(eval(input())) +    S = list(eval(input())) +    c = Counter(S) +    ans = c["R"] * c["G"] * c["B"] +    for i in range(N): +        for j in range(i + 1, N): +            k = j * 2 - i +            if k > N - 1: +                break +            if S[i] != S[j] and S[j] != S[k] and S[i] != S[k]: +                ans -= 1 +    return ans + + +print((solve()))