Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
S = input()

l_r = []
l_g = []
l_b = []
for i in range(N):
  if S[i]=='R':
    l_r.append(i)
  if S[i]=='G':
    l_g.append(i)
  if S[i]=='B':
    l_b.append(i)

ans = len(l_r)*len(l_g)*len(l_b)

for r in l_r:
  for g in l_g:
    mi = min(r, g)
    ma = max(r, g)
    l = ma - mi
    if ma+l in l_b:
      ans -= 1
    if mi-l in l_b:
      ans -= 1
    if l%2==0 and l//2 + mi in l_b:
      ans -= 1

print(ans)

Fixed submission:
import numpy as np
N = int(input())
S = input()

l_r = set()
l_g = set()
l_b = set()
for i in range(N):
  if S[i]=='R':
    l_r.add(i)
  if S[i]=='G':
    l_g.add(i)
  if S[i]=='B':
    l_b.add(i)

ans = len(l_r)*len(l_g)*len(l_b)

for r in l_r:
  for g in l_g:
    mi = min(r, g)
    ma = max(r, g)
    l = ma - mi
    if ma+l in l_b:
      ans -= 1
    if mi-l in l_b:
      ans -= 1
    if l%2==0 and l//2 + mi in l_b:
      ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
S = input()
 
l_r = [i for i, s in enumerate(S) if s=='R']
l_g = [i for i, s in enumerate(S) if s=='G']
l_b = [i for i, s in enumerate(S) if s=='B']
 
ans = len(l_r)*len(l_g)*len(l_b)

for r in l_r:
  for g in l_g:
    mi = min(r, g)
    ma = max(r, g)
    l = ma - mi
    if ma+l in l_b:
      ans -= 1
    if mi-l in l_b:
      ans -= 1
    if l%2==0 and l//2 + mi in l_b:
      ans -= 1

print(ans)

Fixed submission:
import numpy as np
N = int(input())
S = input()

l_r = set()
l_g = set()
l_b = set()
for i in range(N):
  if S[i]=='R':
    l_r.add(i)
  if S[i]=='G':
    l_g.add(i)
  if S[i]=='B':
    l_b.add(i)

ans = len(l_r)*len(l_g)*len(l_b)

for r in l_r:
  for g in l_g:
    mi = min(r, g)
    ma = max(r, g)
    l = ma - mi
    if ma+l in l_b:
      ans -= 1
    if mi-l in l_b:
      ans -= 1
    if l%2==0 and l//2 + mi in l_b:
      ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
S = input()

l_r = [i for i, s in enumerate(S) if s=='R']
l_g = [i for i, s in enumerate(S) if s=='G']
l_b = [i for i, s in enumerate(S) if s=='B']

ans = len(l_r)*len(l_g)*len(l_b)

for dis in range(1, N//2+1):
  for i in range(1, N-2*dis+1):
    j = i+dis
    k = j+dis
    if len(set([S[i-1], S[j-1], S[k-1]]))==3:
      ans -= 1
      
print(ans)

Fixed submission:
import numpy as np
N = int(input())
S = input()

l_r = set()
l_g = set()
l_b = set()
for i in range(N):
  if S[i]=='R':
    l_r.add(i)
  if S[i]=='G':
    l_g.add(i)
  if S[i]=='B':
    l_b.add(i)

ans = len(l_r)*len(l_g)*len(l_b)

for r in l_r:
  for g in l_g:
    mi = min(r, g)
    ma = max(r, g)
    l = ma - mi
    if ma+l in l_b:
      ans -= 1
    if mi-l in l_b:
      ans -= 1
    if l%2==0 and l//2 + mi in l_b:
      ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
S = input()

l_r = [i for i, s in enumerate(S) if s=='R']
l_g = [i for i, s in enumerate(S) if s=='G']
l_b = [i for i, s in enumerate(S) if s=='B']

ans = len(l_r)*len(l_g)*len(l_b)

for r in l_r:
  for g in l_g:
    li = np.sort(np.array([r, g]))
    tmp = li[1]*2 -li[0]
    if tmp in l_b:
      ans -= 1
    
    tmp = (li[0]+li[1])/2
    if tmp in l_b:
   	  ans -= 1
      
    tmp = 2*li[0] - li[1]
    if tmp in l_b:
   	  ans -= 1

print(ans)


Fixed submission:
import numpy as np
N = int(input())
S = input()

l_r = set()
l_g = set()
l_b = set()
for i in range(N):
  if S[i]=='R':
    l_r.add(i)
  if S[i]=='G':
    l_g.add(i)
  if S[i]=='B':
    l_b.add(i)

ans = len(l_r)*len(l_g)*len(l_b)

for r in l_r:
  for g in l_g:
    mi = min(r, g)
    ma = max(r, g)
    l = ma - mi
    if ma+l in l_b:
      ans -= 1
    if mi-l in l_b:
      ans -= 1
    if l%2==0 and l//2 + mi in l_b:
      ans -= 1

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import numpy as np
N = int(input())
S = input()

l_r = [i for i, s in enumerate(S) if s=='R']
l_g = [i for i, s in enumerate(S) if s=='G']
l_b = [i for i, s in enumerate(S) if s=='B']

ans = 0
for r in l_r:
  for g in l_g:
    for b in l_b:
      li = np.sort(np.array([r, g, b]))
      if abs(li[0]-li[1]) != abs(li[1]-li[2]):
        ans += 1

print(ans)


Fixed submission:
import numpy as np
N = int(input())
S = input()

l_r = set()
l_g = set()
l_b = set()
for i in range(N):
  if S[i]=='R':
    l_r.add(i)
  if S[i]=='G':
    l_g.add(i)
  if S[i]=='B':
    l_b.add(i)

ans = len(l_r)*len(l_g)*len(l_b)

for r in l_r:
  for g in l_g:
    mi = min(r, g)
    ma = max(r, g)
    l = ma - mi
    if ma+l in l_b:
      ans -= 1
    if mi-l in l_b:
      ans -= 1
    if l%2==0 and l//2 + mi in l_b:
      ans -= 1

print(ans)