Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r = []
g = []
b = []
res = 0
for i in range(n):
  if s[i] == 'R':
    r.append(i)
  elif s[i] == 'G':
    g.append(i)
  else:
    b.append(i)
for i in b:
  for j in r:
    res += len(g) - int((i + j) / 2 in g) - int(2 * i - j in g) - int(2 * j - i in g)
print(res)


Fixed submission:
n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
  if s[i]=='R':
    R.append(i+1)
  elif s[i]=='G':
    G[i+1]=G.get(i+1,0)+1
  else:
    B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
  for j in B:
    if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
      res-=1
    if G.get(2*max(i,j)-min(i,j),0)==1:
      res-=1
    if G.get(2*min(i,j)-max(i,j),0)==1:
      res-=1
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r = []
g = []
b = []
res = 0
for i in range(n):
  if s[i] == 'R':
    r.append(i)
  elif s[i] == 'G':
    g.append(i)
  else:
    b.append(i)
if max(len(r),len(g),len(b)) == len(b):
  for i in g:
    for j in r:
      res += len(b) - int((i + j) / 2 in b) - int(2 * i - j in b) - int(2 * j - i in b)
else:
  for i in b:
    for j in r:
      res += len(g) - int((i + j) / 2 in g) - int(2 * i - j in g) - int(2 * j - i in g)
print(res)


Fixed submission:
n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
  if s[i]=='R':
    R.append(i+1)
  elif s[i]=='G':
    G[i+1]=G.get(i+1,0)+1
  else:
    B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
  for j in B:
    if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
      res-=1
    if G.get(2*max(i,j)-min(i,j),0)==1:
      res-=1
    if G.get(2*min(i,j)-max(i,j),0)==1:
      res-=1
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
r = []
g = []
b = []
res = 0
for i in range(n):
  if s[i] == 'R':
    r.append(i)
  elif s[i] == 'G':
    g.append(i)
  else:
    b.append(i)
if max(len(r),len(g),len(b)) == len(b):
  for i in g:
    for j in r:
      res += len(b) - b.count((i + j) / 2) - b.count( 2 * i - j) - b.count(2 * j - i)
else:
  for i in b:
    for j in r:
      res += len(g) - g.count((i + j) / 2) - g.count( 2 * i - j) - g.count(2 * j - i)
print(res)


Fixed submission:
n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
  if s[i]=='R':
    R.append(i+1)
  elif s[i]=='G':
    G[i+1]=G.get(i+1,0)+1
  else:
    B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
  for j in B:
    if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
      res-=1
    if G.get(2*max(i,j)-min(i,j),0)==1:
      res-=1
    if G.get(2*min(i,j)-max(i,j),0)==1:
      res-=1
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = 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)
res = 0
if max(len(r),len(g),len(b)) == len(r):
  for i in g:
    for j in b:
      res += len(r) - r.count((i + j) / 2) - r.count( 2 * i - j) - r.count(2 * j - i)
else:
  for i in b:
    for j in r:
      res += len(g) - g.count((i + j) / 2) - g.count( 2 * i - j) - g.count(2 * j - i)
print(res)


Fixed submission:
n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
  if s[i]=='R':
    R.append(i+1)
  elif s[i]=='G':
    G[i+1]=G.get(i+1,0)+1
  else:
    B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
  for j in B:
    if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
      res-=1
    if G.get(2*max(i,j)-min(i,j),0)==1:
      res-=1
    if G.get(2*min(i,j)-max(i,j),0)==1:
      res-=1
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = 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)
res = 0
if max(len(r),len(g),len(b)) == len(r):
  for i in g:
    for j in b:
      flg = 0
      if (i + j) / 2 in r:
        flg += 1
      if 2 * i - j in r:
        flg += 1
      if 2 * j - i in r:
        flg += 1
      res += len(r) - flg
else:
  for i in b:
    for j in r:
      flg = 0
      if (i + j) / 2 in g:
        flg += 1
      if 2 * i - j in g:
        flg += 1
      if 2 * j - i in g:
        flg += 1
      res += len(g) - flg
print(res)


Fixed submission:
n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
  if s[i]=='R':
    R.append(i+1)
  elif s[i]=='G':
    G[i+1]=G.get(i+1,0)+1
  else:
    B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
  for j in B:
    if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
      res-=1
    if G.get(2*max(i,j)-min(i,j),0)==1:
      res-=1
    if G.get(2*min(i,j)-max(i,j),0)==1:
      res-=1
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = 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)
res = 0
if max(len(r),len(g),len(b)) == len(r):
  for i in g:
    for j in b:
      flg = 0
      if (i + j) / 2 in r:
        flg += 1
      if 2 * i - j in r:
        flg += 1
      if 2 * j - i in r:
        flg += 1
      res += len(r) - flg
else:
  for i in g:
    for j in r:
      flg = 0
      if (i + j) / 2 in b:
        flg += 1
      if 2 * i - j in b:
        flg += 1
      if 2 * j - i in b:
        flg += 1
      res += len(b) - flg
print(res)


Fixed submission:
n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
  if s[i]=='R':
    R.append(i+1)
  elif s[i]=='G':
    G[i+1]=G.get(i+1,0)+1
  else:
    B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
  for j in B:
    if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
      res-=1
    if G.get(2*max(i,j)-min(i,j),0)==1:
      res-=1
    if G.get(2*min(i,j)-max(i,j),0)==1:
      res-=1
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = 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)
res = 0
if max(len(r),len(g),len(b)) == len(g):
  for i in r:
    for j in b:
      flg = 0
      if (i + j) / 2 in g:
        flg += 1
      if 2 * i - j in g:
        flg += 1
      if 2 * j - i in g:
        flg += 1
      res += len(g) - flg
else:
  for i in g:
    for j in r:
      flg = 0
      if (i + j) / 2 in b:
        flg += 1
      if 2 * i - j in b:
        flg += 1
      if 2 * j - i in b:
        flg += 1
      res += len(b) - flg
print(res)


Fixed submission:
n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
  if s[i]=='R':
    R.append(i+1)
  elif s[i]=='G':
    G[i+1]=G.get(i+1,0)+1
  else:
    B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
  for j in B:
    if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
      res-=1
    if G.get(2*max(i,j)-min(i,j),0)==1:
      res-=1
    if G.get(2*min(i,j)-max(i,j),0)==1:
      res-=1
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = 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)
res = 0
for i in r:
  for j in b:
    flg = 0
    if (i + j) / 2 in g:
      flg += 1
    if 2 * i - j in g:
      flg += 1
    if 2 * j - i in g:
      flg += 1
    res += len(g) - flg
print(res)


Fixed submission:
n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
  if s[i]=='R':
    R.append(i+1)
  elif s[i]=='G':
    G[i+1]=G.get(i+1,0)+1
  else:
    B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
  for j in B:
    if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
      res-=1
    if G.get(2*max(i,j)-min(i,j),0)==1:
      res-=1
    if G.get(2*min(i,j)-max(i,j),0)==1:
      res-=1
print(res)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = 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)
res = 0
for i in r:
  for j in b:
    for k in g:
      if (i + j) / 2 != k and (j + k) / 2 != i and (k + i) / 2 != j:
        res += 1
print(res)


Fixed submission:
n=int(input())
s=input()
R=[]
G={}
B=[]
for i in range(n):
  if s[i]=='R':
    R.append(i+1)
  elif s[i]=='G':
    G[i+1]=G.get(i+1,0)+1
  else:
    B.append(i+1)
res=len(R)*len(G)*len(B)
for i in R:
  for j in B:
    if ((i+j)%2==0 and G.get((i+j)//2,0)==1):
      res-=1
    if G.get(2*max(i,j)-min(i,j),0)==1:
      res-=1
    if G.get(2*min(i,j)-max(i,j),0)==1:
      res-=1
print(res)