Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
if n<=2:
    print(0)
    quit()
import itertools           
for i,j,k in itertools.combinations_with_replacement(range(0,n), 3):
    si,sj,sk=s[i],s[j],s[k]
    if 2*j!=i+k and si!=sj and si!=sk and sj!=sk:
        cnt+=1
print(cnt)


Fixed submission:
n = int(input())
s =     input()
if n < 3:
  print(0)
  exit

result = 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 and s[k] != s[i] and s[k] != s[j] and s[j] != s[i]:
      result -= 1

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
if n<=2:
    print(0)
    quit()
import itertools           
for i,j,k in itertools.combinations_with_replacement(range(0,n), 3):
    si,sj,sk=s[i],s[j],s[k]
    if j-i!=k-j and si!=sj and si!=sk and sj!=sk:
        cnt+=1
print(cnt)


Fixed submission:
n = int(input())
s =     input()
if n < 3:
  print(0)
  exit

result = 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 and s[k] != s[i] and s[k] != s[j] and s[j] != s[i]:
      result -= 1

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
if n<=3:
    print(0)
    quit()
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i]!=s[j]:
            for k in range(j+1,n):
                if s[k]!=s[i] and s[k]!=s[j] and j-i!=k-j:
                    cnt+=1
print(cnt)
            


Fixed submission:
n = int(input())
s =     input()
if n < 3:
  print(0)
  exit

result = 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 and s[k] != s[i] and s[k] != s[j] and s[j] != s[i]:
      result -= 1

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
if n<=2:
    print(0)
    quit()
import itertools           
for i,j,k in itertools.combinations_with_replacement(range(0,n), 3):
    if j-i!=k-j and s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
        cnt+=1
print(cnt)


Fixed submission:
n = int(input())
s =     input()
if n < 3:
  print(0)
  exit

result = 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 and s[k] != s[i] and s[k] != s[j] and s[j] != s[i]:
      result -= 1

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
if n<=3:
    print(0)
    quit()
for i in range(n-2):
    si=s[i]
    for j in range(i+1,n-1):
        sj=s[j]
        if si!=sj:
            for k in range(j+1,n):
                sk=s[k]
                if sk!=si and sk!=sj and j-i!=k-j:
                    cnt+=1
print(cnt)
            


Fixed submission:
n = int(input())
s =     input()
if n < 3:
  print(0)
  exit

result = 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 and s[k] != s[i] and s[k] != s[j] and s[j] != s[i]:
      result -= 1

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
if n<=2:
    print(0)
    quit()
for i in range(n-2):
    si=s[i]
    for j in range(i+1,n-1):
        sj=s[j]
        if si!=sj:
            for k in range(j+1,n):
                sk=s[k]
                if sk!=si and sk!=sj and j-i!=k-j:
                    cnt+=1
print(cnt)
            


Fixed submission:
n = int(input())
s =     input()
if n < 3:
  print(0)
  exit

result = 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 and s[k] != s[i] and s[k] != s[j] and s[j] != s[i]:
      result -= 1

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
if n<=2:
    print(0)
    quit()
import itertools           
for i,j,k in itertools.combinations_with_replacement(range(0,n), 3):
    if j-i!=k-j and s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
        cnt+=1
print(cnt)


Fixed submission:
n = int(input())
s =     input()
if n < 3:
  print(0)
  exit

result = 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 and s[k] != s[i] and s[k] != s[j] and s[j] != s[i]:
      result -= 1

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
if n<=2:
    print(0)
    quit()
import itertools           
for i,j,k in itertools.combinations_with_replacement(range(0,n), 3):
    if j-i!=k-j and s[i]!=s[j] and s[i]!=s[k] and s[j]!=s[k]:
        cnt+=1
print(cnt)


Fixed submission:
n = int(input())
s =     input()
if n < 3:
  print(0)
  exit

result = 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 and s[k] != s[i] and s[k] != s[j] and s[j] != s[i]:
      result -= 1

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
if n<=2:
    print(0)
    quit()
for i in range(n-2):
    si=s[i]
    for j in range(i+1,n-1):
        sj=s[j]
        if si!=sj:
            for k in range(j+1,n):
                sk=s[k]
                if sk!=si and sk!=sj and j-i!=k-j:
                    cnt+=1
print(cnt)
            


Fixed submission:
n = int(input())
s =     input()
if n < 3:
  print(0)
  exit

result = 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 and s[k] != s[i] and s[k] != s[j] and s[j] != s[i]:
      result -= 1

print(result)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=input()
cnt=0
if n<=2:
    print(0)
    quit()
for i in range(n-2):
    si=s[i]
    for j in range(i+1,n-1):
        sj=s[j]
        if si!=sj:
            for k in range(j+1,n):
                sk=s[k]
                if sk!=si and sk!=sj and j-i!=k-j:
                    cnt+=1
print(cnt)
            


Fixed submission:
n = int(input())
s =     input()
if n < 3:
  print(0)
  exit

result = 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 and s[k] != s[i] and s[k] != s[j] and s[j] != s[i]:
      result -= 1

print(result)