N=int(eval(input()))

S=[1 if x=='R' else (2 if x=='G' else 3) for x in [*eval(input())]]



t=S.count(1)*S.count(2)*S.count(3)

for i in range(N-2):

  j=1

  while i+2*j<N:

    if S[i]*S[i+j]*S[i+2*j]==6:

      t-=1

    j+=1



print(t)

def main():

  N=int(eval(input()))

  S=[1 if x=='R' else (2 if x=='G' else 3) for x in [*eval(input())]]



  t=S.count(1)*S.count(2)*S.count(3)

  for i in range(N-2):

    j=1

    while i+2*j<N:

      if S[i]*S[i+j]*S[i+2*j]==6:

        t-=1

      j+=1



  print(t)



main()

N = int(eval(input()))
S = [1 if x == "R" else (2 if x == "G" else 3) for x in [*eval(input())]]
t = S.count(1) * S.count(2) * S.count(3)
for i in range(N - 2):
    j = 1
    while i + 2 * j < N:
        if S[i] * S[i + j] * S[i + 2 * j] == 6:
            t -= 1
        j += 1
print(t)

def main():
    N = int(eval(input()))
    S = [1 if x == "R" else (2 if x == "G" else 3) for x in [*eval(input())]]
    t = S.count(1) * S.count(2) * S.count(3)
    for i in range(N - 2):
        j = 1
        while i + 2 * j < N:
            if S[i] * S[i + j] * S[i + 2 * j] == 6:
                t -= 1
            j += 1
    print(t)


main()

-N = int(eval(input())) -S = [1 if x == "R" else (2 if x == "G" else 3) for x in [*eval(input())]] -t = S.count(1) * S.count(2) * S.count(3) -for i in range(N - 2): -    j = 1 -    while i + 2 * j < N: -        if S[i] * S[i + j] * S[i + 2 * j] == 6: -            t -= 1 -        j += 1 -print(t) +def main(): +    N = int(eval(input())) +    S = [1 if x == "R" else (2 if x == "G" else 3) for x in [*eval(input())]] +    t = S.count(1) * S.count(2) * S.count(3) +    for i in range(N - 2): +        j = 1 +        while i + 2 * j < N: +            if S[i] * S[i + j] * S[i + 2 * j] == 6: +                t -= 1 +            j += 1 +    print(t) + + +main()