Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=str(input())
if n<=2:
    print(0)
    exit()
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b
def moji(in1,in2):
    l=['R','G','B']
    l.remove(in1)
    l.remove(in2)
    return l[0]
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i]==s[j]:
            continue
        m=moji(s[i],s[j])
        if 2*j-i<=n-1:
          if s[2*j-i]==m:
            ans-=1
print(ans)

Fixed submission:
n=int(input())
s=str(input())
if n<=2:
    print(0)
    exit()
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i>n-1:
            break
        if s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=str(input())
if n<=2:
    print(0)
    exit()
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b
def moji(in1,in2):
    l=['R','G','B']
    l.remove(in1)
    l.remove(in2)
    return l[0]
for i in range(n-2):
    for j in range(i+1,n-1):
        if s[i]==s[j]:
            continue
        m=moji(s[i],s[j])
        if 2*j-i<=n-1:
          if s[2*j-i]==m:
            ans-=1
print(ans)

Fixed submission:
n=int(input())
s=str(input())
if n<=2:
    print(0)
    exit()
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i>n-1:
            break
        if s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
input = sys.stdin.readline
def main():
  n=int(input())
  s=str(input())
  r=[]
  g=[]
  b=[]
  for i in range(n):
    if s[i]=='R':
      r.append(i)
    elif s[i]=='G':
      g.append(i)
    else:
      b.append(i)
  ans=0
  for l in r:
    for m in g:
      for k in b:
        if abs(m-l)!=abs(k-m) and abs(k-l)!=abs(k-m) and abs(k-l)!=abs(l-m):
          ans+=1
  print(ans)
main()

Fixed submission:
n=int(input())
s=str(input())
if n<=2:
    print(0)
    exit()
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i>n-1:
            break
        if s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=str(input())
r=[]
g=[]
b=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=0
for l in r:
  for m in g:
    for k in b:
      if abs(m-l)!=abs(k-m) and abs(k-l)!=abs(k-m) and abs(k-l)!=abs(l-m):
        ans+=1
print(ans)

Fixed submission:
n=int(input())
s=str(input())
if n<=2:
    print(0)
    exit()
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i>n-1:
            break
        if s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=str(input())
r=[]
g=[]
b=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=0
for l in r:
  for m in g:
    for k in b:
      if l!=m and m!=k and k!=m and abs(m-l)!=abs(k-m) and abs(k-l)!=abs(k-m) and abs(k-l)!=abs(l-m):
        ans+=1
print(ans)

Fixed submission:
n=int(input())
s=str(input())
if n<=2:
    print(0)
    exit()
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i>n-1:
            break
        if s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
            ans-=1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
s=str(input())
r=[]
g=[]
b=[]
for i in range(n):
  if s[i]=='R':
    r.append(i)
  elif s[i]=='G':
    g.append(i)
  else:
    b.append(i)
ans=0
for l in r:
  for m in g:
    for k in b:
      if l!=m and m!=k and k!=m and abs(m-l)!=abs(k-m) and abs(k-l)!=abs(k-m) and abs(k-l)!=abs(l-m):
        ans+=1
print(ans)

Fixed submission:
n=int(input())
s=str(input())
if n<=2:
    print(0)
    exit()
r=s.count('R')
g=s.count('G')
b=s.count('B')
ans=r*g*b
for i in range(n-2):
    for j in range(i+1,n-1):
        if 2*j-i>n-1:
            break
        if s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
            ans-=1
print(ans)