qyliang/CodeNanoFix huggingface dataset:
Buggy code:
N=int(input())
S=input()

ans = S.count("R")*S.count("G")*S.count("B")

tmp=0

for i in range(N):
  for j in range(i,N):
    if j-i+j < N:
      if S[i]==S[j] and S[j]==S[j-i+j] and S[i]==S[j-i+j]
        tmp += 1

ans = ans - tmp
print(ans)

Fixed code:
N=int(input())
S=input()

ans = S.count("R")*S.count("G")*S.count("B")

tmp=0

for i in range(N):
  for j in range(i,N):
    if j-i+j < N:
      if S[i]!=S[j] and S[j]!=S[j-i+j] and S[i]!=S[j-i+j]:
        tmp += 1

ans = ans - tmp
print(ans)
Buggy code:
N = int(input())
l = [1] * N
i = 0
d = {1:0,2:0,3:0}
for s in input():
    n = 1
    if s == "G":
        n = 2
    elif s == "B":
        n = 3
    l[i] = n
    d[n] += 1
    i += 1
cnt = d[1] * d[2] * d[3]
for j in range(1,(N - 1) // 2):
    for k in range(N - (2 * j)):
        if l[k] * l[k+j] * l[k+j+j] == 6:
            cnt -= 1
print(cnt)



Fixed code:
N = int(input())
l = [1] * N
i = 0
d = {1:0,2:0,3:0}
for s in input():
    n = 1
    if s == "G":
        n = 2
    elif s == "B":
        n = 3
    l[i] = n
    d[n] += 1
    i += 1
cnt = d[1] * d[2] * d[3]
for j in range(1,(N - 1) // 2 + 1):
    for k in range(N - (2 * j)):
        if l[k] * l[k+j] * l[k+j+j] == 6:
            cnt -= 1
print(cnt)
Buggy code:
from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = {i for i, x in enumerate(x2) if x == "B"}

R = len(R_i)
G = len(G_i)
# B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)

Fixed code:
from itertools import product

x1 = int(input())
x2 = input()

R_i = [i for i, x in enumerate(x2) if x == "R"]
G_i = [i for i, x in enumerate(x2) if x == "G"]
B_i = {i for i, x in enumerate(x2) if x == "B"}

R = len(R_i)
G = len(G_i)
B = len(B_i)

xs = map(sorted, product(R_i, G_i))

s = 0
for a in xs:
    k = a[1]*2 - a[0]  # 2j-i
    if k in B_i:
        s +=1
    i = a[0]*2 - a[1]  # 2j-k
    if i in B_i:
        s +=1
    j = (a[0] + a[1]) / 2
    if j.is_integer():
        j = int(j)
        if j in B_i:
            s +=1
print(R*G*B - s)
Buggy code:
N=int(input())
S=list(input())
a=[0]*4

for i in range(N):
  if S[i]=='R':a[0]+=1
  if S[i]=='G':a[1]+=1
  if S[i]=='B':a[2]+=1
    
for i in range(N):
  for j in range(i+1,N):
    k=j+(j-i)
    if k>=N:
      break
    else:
      if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i] and j-i==k-j:
        a[3]+=1

print(a)
print(a[0]*a[1]*a[2]-a[3])

Fixed code:
N=int(input())
S=list(input())
a=[0]*4

for i in range(N):
  if S[i]=='R':a[0]+=1
  if S[i]=='G':a[1]+=1
  if S[i]=='B':a[2]+=1
    
for i in range(N):
  for j in range(i+1,N):
    k=j+(j-i)
    if k>=N:
      break
    else:
      if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i] and j-i==k-j:
        a[3]+=1

print(a[0]*a[1]*a[2]-a[3])
Buggy code:
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b

for i in range(n):
    for d in range(n):
        j=i+d
        k=j+d
        if k>=n:
            break
        if s[i]!=s[j] & s[j]!=s[k] & s[k]!=s[i]:
            ans-=1

print(ans)

Fixed code:
n=int(input())
s=input()
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b

for i in range(n):
    for d in range(n):
        j=i+d
        k=j+d
        if k>=n:
            break
        if (s[i]!=s[j]) & (s[j]!=s[k]) & (s[k]!=s[i]):
            ans-=1

print(ans)
Buggy code:
import math
n =  int(input())
s = list(input())

upper = s.count("R")*s.count("G")*s.count("B")

minus = [0]*(n+1)
if s[0]!=s[1] and s[1]!=s[2] and s[2]!=s[0]:
  minus [3] = 1
else:
  minus [3] = 0

def counting(x):
  count = 0
  for i in range(math.ceil(x/2)):
    if s[x-1]!=s[x-1-i] and s[x-1-i]!=s[x-1-2*i] and s[x-1-2*i]!=s[x-1]:
      count += 1
    else:
      count += 0
  return count

for i in range(4,n):
  minus[i+1] = minus[i]+counting(i+1)

print(int(upper-minus[n]))

Fixed code:
import math
n =  int(input())
s = list(input())

upper = s.count("R")*s.count("G")*s.count("B")

def counting(x):
  count = 0
  for i in range(1, math.ceil(x/2)):
    if s[x-1]!=s[x-1-i] and s[x-1-i]!=s[x-1-2*i] and s[x-1-2*i]!=s[x-1]:
      count += 1
    else:
      count += 0
  return count

if n>=3:
  minus = [0]*(n+1)
  if s[0]!=s[1] and s[1]!=s[2] and s[2]!=s[0]:
    minus [3] = 1
  else:
    minus [3] = 0
  for i in range(3,n):
    minus[i+1] = minus[i]+counting(i+1)
  print(int(upper-minus[n]))
else:
  print(int(0))
Buggy code:
N=int(input())
A=input()
c=0
B1B=0
B1R=0
B1G=0
if A[0]=="B":
 B1B+=1
elif A[0]=="R":
 B1R+=1
else:
 B1G+=1
for i in range(N-2):
 B2=A[i+1]
 for k in range(N-i-2):
  B3=A[i+2+k]
  if (B2=="B" and B3=="R")or (B2=="R" and B3=="B"):
   c+=B1G
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="G":
     c-=1
  if (B2=="G" and B3=="R")or (B2=="R" and B3=="G"):
   c+=B1B
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="B":
     c-=1
  if (B2=="B" and B3=="G")or (B2=="G" and B3=="B"):
   c+=B1R
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="R":
     c-=1
  if B2=="B":
   B1B+=1
  elif B2=="R":
   B1R+=1
  else:
   B1G+=1
print(c)


Fixed code:
N=int(input())
A=input()
c=0
B1B=0
B1R=0
B1G=0
if A[0]=="B":
 B1B+=1
elif A[0]=="R":
 B1R+=1
else:
 B1G+=1
for i in range(N-2):
 B2=A[i+1]
 for k in range(N-i-2):
  B3=A[i+2+k]
  if (B2=="B" and B3=="R")or (B2=="R" and B3=="B"):
   c+=B1G
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="G":
     c-=1
  if (B2=="G" and B3=="R")or (B2=="R" and B3=="G"):
   c+=B1B
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="B":
     c-=1
  if (B2=="B" and B3=="G")or (B2=="G" and B3=="B"):
   c+=B1R
   if (i+2+k)<=(i+1)*2:
    if A[(i+1)*2-(i+2+k)]=="R":
     c-=1
 if B2=="B":
  B1B+=1
 elif B2=="R":
  B1R+=1
 else:
  B1G+=1
print(c)
Buggy code:
n = int(input())
s = str(input())
rn = s.count("R")
gn = s.count("G")
bn = s.count("B")

ct=0
for i in range(n):
  for j in range(i+1,n):
    k = 2*j - i
    if k = n:
      break
    elif s[i]!=s[j] and s[j]!=s[k]and s[i]!=s[k]:
      ct += 1
 
print(rn*gn*bn-ct)

Fixed code:
n = int(input())
s = str(input())
rn = s.count("R")
gn = s.count("G")
bn = s.count("B")

ct=0
for i in range(n):
  for j in range(i+1,n):
    if 2*j - i >= n:
      break
    elif s[i]!=s[j] and s[j]!=s[2*j-i] and s[i]!=s[2*j-i]:
      ct += 1
 
print(rn*gn*bn-ct)
Buggy code:
n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] == str[j] or str[i] == str[k] or str[j] == str[k] :
        sum -= 1
    
print(sum)

Fixed code:
n = int(input())
 
str = input()

r = str.count('R')
g = str.count('G')
b = str.count('B')
sum = r * g * b
for i in range(n-2):
  for j in range(i+1, n-1):
    k = 2 * j - i
    if k < n:
      if str[i] != str[j] and str[i] != str[k] and str[j] != str[k] :
        sum -= 1
    
print(sum)
Buggy code:

def main():
    n = int(input())
    s = input()
    r,g,b = 0,0,0
    for i in s:
        if i == 'r': r += 1
        elif i == 'g': g += 1
        elif i == 'b': b += 1
    ans = r*g*b
    for j in range(n):
        for i in range(j):
            k = j+(j-i)
            if k < n:
                if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]:
                    continue
                ans -= 1
    print(ans)
if __name__ == "__main__":
    main()

Fixed code:

def main():
    n = int(input())
    s = input()
    r,g,b = 0,0,0
    for i in s:
        if i == 'R': r += 1
        elif i == 'G': g += 1
        elif i == 'B': b += 1
    ans = r*g*b
    for j in range(n):
        for i in range(j):
            k = j+(j-i)
            if k < n:
                if s[i] == s[j] or s[i] == s[k] or s[k] == s[j]:
                    continue
                ans -= 1
    print(ans)
if __name__ == "__main__":
    main()
Buggy code:
n,s=open(0)
n=int(n)
s=[ord(c)%3for c in s]
d=[0]*3
for i in s:d[i]+=1
a=0
for i in range(n):
    d[s[i]]-=1
    b=d.copy()
    for j in range(i+1,n):
        b[s[j]]-=1
        if s[i]==s[j]:continue
        c=(0,2,1,0)[s[i]+s[j]]
        a+=b[c]
        k=j+j-i
        if k<n and s[k]==c:
            a-=1
print(a)

Fixed code:
n=int(input())
s=[ord(c)%3for c in input()]
d=[0]*3
for i in s:d[i]+=1
a=0
for i in range(n):
    d[s[i]]-=1
    b=d.copy()
    for j in range(i+1,n):
        b[s[j]]-=1
        if s[i]==s[j]:continue
        c=(0,2,1,0)[s[i]+s[j]]
        a+=b[c]
        k=j+j-i
        if k<n and s[k]==c:
            a-=1
print(a)
Buggy code:
n = int(input())
s = input()

r = [0] * (n+1)
g = [0] * (n+1)
b = [0] * (n+1)
for i, c in enumerate(reversed(s), 1):
    if c == 'R':
        r[i] += r[i-1] + 1
    else:
        r[i] += r[i-1]
    
    if c == 'G':
        g[i] += g[i-1] + 1
    else:
        g[i] += g[i-1]
    
    if c == 'B':
        b[i] += b[i-1] + 1
    else:
        b[i] += b[i-1]

# print(r[:-1][::-1])
# print(g[:-1][::-1])
# print(b[:-1][::-1])

ans=0
for i in range(n-2):
    for j in range(i+1, n-1):
        if s[i] == s[j]:
            continue
        se = set('RGB') - set(s[i] + s[j])
        c = se.pop()
        print('i=',i,'j=',j,'c=',c)
        if c == 'R':
            ans += r[j]
            if 2*j-i < n and s[2*j-i] == 'R':
                ans -= 1
        elif c == 'G':
            ans += g[j]
            if 2*j-i < n and s[2*j-i] == 'G':
                ans -= 1
        elif c == 'B':
            ans += b[j]
            if 2*j-i < n and s[2*j-i] == 'B':
                ans -= 1
print(ans)

Fixed code:
n = int(input())
s = input()

r = [0] * (n+1)
g = [0] * (n+1)
b = [0] * (n+1)
for i, c in enumerate(reversed(s), 1):
    if c == 'R':
        r[i] += r[i-1] + 1
    else:
        r[i] += r[i-1]
    
    if c == 'G':
        g[i] += g[i-1] + 1
    else:
        g[i] += g[i-1]
    
    if c == 'B':
        b[i] += b[i-1] + 1
    else:
        b[i] += b[i-1]

r = r[:-1][::-1]
g = g[:-1][::-1]
b = b[:-1][::-1]

ans=0
for i in range(n-2):
    for j in range(i+1, n-1):
        if s[i] == s[j]:
            continue
        se = set('RGB') - set(s[i] + s[j])
        c = se.pop()
        if c == 'R':
            ans += r[j]
            if 2*j-i < n and s[2*j-i] == 'R':
                ans -= 1
        elif c == 'G':
            # print('j=',j,'g[j]=',g[j])
            ans += g[j]
            if 2*j-i < n and s[2*j-i] == 'G':
                ans -= 1
        elif c == 'B':
            ans += b[j]
            if 2*j-i < n and s[2*j-i] == 'B':
                ans -= 1
        # print('i=',i,'j=',j,'c=',c, 'ans=',ans)
print(ans)
Buggy code:
n=int(input())
s=input()
r=s.count('R')
g=s.count('G')
b=s.count('B')
cnt=0
for i in range(n-2):
    for j in range(1, min(i+1, n-i)):
            if (s[i] != s[i-j]) and (s[i] != s[i+j]) and (s[i-j] != s[i+j]):
                cnt += 1
print(r*g*b-cnt)

Fixed code:
n=int(input())
s=input()
r=s.count('R')
g=s.count('G')
b=s.count('B')
cnt=0
for i in range(n-1):
    for j in range(1, min(i+1, n-i)):
            if (s[i] != s[i-j]) and (s[i] != s[i+j]) and (s[i-j] != s[i+j]):
                cnt += 1
print(r*g*b-cnt)
Buggy code:
n = int(input())
s = input()
ans = 0
ans_list = []

R_index = []
G_index = []
B_index = []

for i in range(n):
    if s[i] == 'R':
        R_index.append(i)
    elif s[i] == 'G':
        G_index.append(i)
    elif s[i] == 'B':
        B_index.append(i)

ans = len(R_index) * len(G_index) * len(B_index)

for j in range(1, n-1):
    for i in range(min(n-j-1,j)):
        if s[j-i] != s[j] and s[j] != s[j+i] and s[j-i] != s[j+i]:
            ans -= 1


print(ans)


Fixed code:
n = int(input())
s = input()
ans = 0
ans_list = []

R_index = []
G_index = []
B_index = []

for i in range(n):
    if s[i] == 'R':
        R_index.append(i)
    elif s[i] == 'G':
        G_index.append(i)
    elif s[i] == 'B':
        B_index.append(i)

ans = len(R_index) * len(G_index) * len(B_index)

for j in range(1, n-1):
    for i in range(min(n-j-1,j)+1):
        # print(j,i)
        # print(min(n-j-1,j))
        #
        # print(s[j-i],s[j],s[j+i])
        if s[j-i] != s[j] and s[j] != s[j+i] and s[j-i] != s[j+i]:
            # print('here')
            ans -= 1

print(ans)
Buggy code:
import collections

n=int(input())
S=input()
s=collections.Counter(S)
print(s)
ans=s['R']*s['G']*s['B']
for i in range(n):
    for d in range(n):
        j=i+d
        k=j+d
        if k>n-1:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)

Fixed code:
#162D
#RGB Triplets

import collections

n=int(input())
S=input()
s=collections.Counter(S)
ans=s['R']*s['G']*s['B']
for i in range(n):
    for d in range(n):
        j=i+d
        k=j+d
        if k>n-1:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans-=1
print(ans)
Buggy code:
S=str(input()) 
N = int(input())

r = S.count('R')
g = S.count('G')
b = S.count('B')
total = r * g * b

k = 0
count = 0
for i in range(N):
    for j in range(N):
        k = 2 * j - i
        if(i>=j or j >=k or i >=k): continue
        if(i==j or j==k or k==i or k<0 or k>=N): continue
        if(S[i] == S[j] or S[j] == S[k] or S[k] == S[i]): continue
        
        count += 1
        
print(total - count)


Fixed code:
N = int(input())
S = str(input()) 

r = S.count('R')
g = S.count('G')
b = S.count('B')
total = r * g * b

k = 0
count = 0
for i in range(N):
    for j in range(N):
        k = 2 * j - i
        if(i>=j or j >=k or i >=k): continue
        if(i==j or j==k or k==i or k<0 or k>=N): continue
        if(S[i] == S[j] or S[j] == S[k] or S[k] == S[i]): continue
        
        count += 1
        
print(total - count)
Buggy code:
length = int(input())
text = input()

r_count = text.count("R")
g_count = text.count("G")
b_count = text.count("B")

answer = r_count * g_count * b_count

for i in range(length-2):
    for j in range(i+1, length-1):
        k = i + (i-j)*2
        if k < length and text[i]!=text[j] and text[i]!=text[k] and text[j]!=text[k]:
            answer -= 1
        
print(answer)

Fixed code:
length = int(input())
text = input()

r_count = text.count("R")
g_count = text.count("G")
b_count = text.count("B")

answer = r_count * g_count * b_count

for i in range(length-2):
    for j in range(i+1, length-1):
        k = i + (j-i)*2
        if k < length and text[i]!=text[j] and text[i]!=text[k] and text[j]!=text[k]:
            answer -= 1
        
print(answer)
Buggy code:
n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1
print(r,g,b)

ans=r*g*b

for i in range(1,n):
  for j in range(n):
    if j+i+i>=n:break
    if(s[j]!=s[j+i] and s[j+i]!=s[j+i+i] and s[j]!=s[j+i+i]):
      ans-=1
print(ans)


Fixed code:
n = int(input())
s = input()

r = 0
g = 0
b = 0

for i in range(n):
    if s[i] == "R":
        r += 1
    elif s[i] == "G":
        g += 1
    else:
        b += 1
ans = r * g * b

for i in range(n):
    for j in range(min(i, n - 1 - i)):
        if s[i]!=s[i+j+1] and s[i]!=s[i-j-1] and s[i+j+1]!=s[i-j-1]:
            ans -= 1

print(ans)
Buggy code:
N = int(input())
S = input()
Sr = Sg = Sb = 0
for c in S:
    if c == 'R':
        Sr += 1
    elif c == 'G':
        Sg += 1
    else:
        Sb += 1
A = Sr * Sg * Sb
for sep in range(1,(N-1)//2):
    for i in range(N-2*sep):
        if S[i] != S[i+sep] and S[i+sep] != S[i+2*sep] and S[i] != S[i+2*sep]:
            A -= 1
print(A)


Fixed code:
N = int(input())
S = input()
Sr = Sg = Sb = 0
for c in S:
    if c == 'R':
        Sr += 1
    elif c == 'G':
        Sg += 1
    else:
        Sb += 1
A = Sr * Sg * Sb
for sep in range(1,(N+1)//2):
    for i in range(N-2*sep):
        if S[i] != S[i+sep] and S[i+sep] != S[i+2*sep] and S[i] != S[i+2*sep]:
            A -= 1
print(A)
Buggy code:
N = int(input())
X = input()
ans = 0
r=0
g=0
b=0
G = []
R = []
B = []
for i in range(0,N):
    if(X[i] == 'G'):
        G.append(i)
        g+=1
for k in range(0,N):
    if(X[k] == 'R'):
        R.append(k)
        r+=1
for j in range(0,N):
    if(X[j] == 'B'):
        B.append(j)
        b+=1
ans = r*b*g
for i in range(0,N-2):
    for j in range(i+1,N-2):
        if(2*j-i < N) and X[i] != X[j]:
            if(X[2*j-i] != X[i]) and (X[2*j-i] != X[j]):
                ans -= 1
print(ans)

Fixed code:
N = int(input())
X = input()
ans = 0
r=0
g=0
b=0
G = []
R = []
B = []
for i in range(0,N):
    if(X[i] == 'G'):
        G.append(i)
        g+=1
for k in range(0,N):
    if(X[k] == 'R'):
        R.append(k)
        r+=1
for j in range(0,N):
    if(X[j] == 'B'):
        B.append(j)
        b+=1
ans = r*b*g
for i in range(0,N):
    for j in range(i+1,N):
        if(2*j-i < N) and X[i] != X[j]:
            if(X[2*j-i] != X[i]) and (X[2*j-i] != X[j]):
                ans -= 1
print(ans)
Buggy code:
import itertools
n = int(input())
s = str(input())
r = {}
b = {}
g = {}
for i in range(len(s)):
    if s[i] == 'R':
        r[i+1] = s[i]
    elif s[i] == 'B':
        b[i+1] = s[i]
    else:
        g[i+1] = s[i]
ans = len(r) * len(b) * len(g)
for i in r.keys():
    for j in b.keys():
        diff = abs(j-i)
        if max(i,j)+diff in g.keys() or min(i,j)-diff in g.keys() or ((i+j)%2 == 0 and (i+j)//2 in g.keys()):
            ans -= 1
print(ans)

Fixed code:
import itertools
n = int(input())
s = str(input())
r = {}
b = {}
g = {}
for i in range(len(s)):
    if s[i] == 'R':
        r[i+1] = s[i]
    elif s[i] == 'B':
        b[i+1] = s[i]
    else:
        g[i+1] = s[i]
ans = len(r) * len(b) * len(g)
for i in r.keys():
    for j in b.keys():
        diff = abs(j-i)
        minb = min(i,j)-diff
        maxb = max(i,j)+diff
        if maxb in g.keys():
            ans -= 1
        if minb in g.keys():
            ans -= 1
        if((i+j)%2==0):
            if((i+j)//2 in g.keys()):
                ans -=1
print(ans)
Buggy code:
N = int(input())
s = input()
 
r_cnt = s.count('R')
g_cnt = s.count('G')
b_cnt = s.count('B')

ans = r_cnt * g_cnt * b_cnt
 
for i in range(N):
    for j in range(i,N):
        k = 2*j - i
        if k >= N:
            break
        elif S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans -= 1

print(ans)

Fixed code:
N = int(input())
S = input()
 
r_cnt = S.count('R')
g_cnt = S.count('G')
b_cnt = S.count('B')

ans = r_cnt * g_cnt * b_cnt
 
for i in range(N):
    for j in range(i,N):
        k = 2*j - i
        if k >= N:
            break
        if S[i]!=S[j] and S[j]!=S[k] and S[k]!=S[i]:
            ans -= 1
#         print(i,j,k)

print(ans)
Buggy code:
n = int(input())
s = input()

count = 0
r=0
g=0
b=0
for i in range(0,n):
  if s[i] == 'R':
    r = r + 1
  if s[i]=='G':
    g = g+1
  if s[i]=='B':
    b = b+1
    
for i in range(0,n-3):
  ii = s[i]
  for j in range(i+1, n-1):
    jj = s[j]
    if ii==jj:
      continue
    if (2*j-i)<=(n-1):
      if ii!=s[2*j-i] and jj!=s[2*j-i]:
        count = count + 1
print(r*g*b-count)


Fixed code:
n = int(input())
s = input()

count = 0
r=0
g=0
b=0
for i in range(0,n):
  if s[i] == 'R':
    r = r + 1
  if s[i]=='G':
    g = g+1
  if s[i]=='B':
    b = b+1
    
for i in range(0,n):
  ii = s[i]
  for j in range(i+1, n):
    jj = s[j]
    if ii==jj:
      continue
    if (2*j-i)<=(n-1):
      if ii!=s[2*j-i] and jj!=s[2*j-i]:
        count = count + 1
print(r*g*b-count)
Buggy code:
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
cnt= 0
for i in range(n):
    for j in range(i,n):
        if s[i] != s[j] and s[i] != s[2*j-i] and s[j] != s[2*j-i] and 2*j-i<n:
            cnt += 1
print(r*g*b-cnt)

Fixed code:
n=int(input())
s=input()
l=len(s)
r=s.count("R")
g=s.count("G")
b=s.count("B")
ans=r*g*b
cnt=0
for j in range(2,l):
    for i in range(1,j):
        if j*2<=i+l:
            if s[i-1]!=s[j-1] and s[j-1]!=s[j*2-i-1] and s[i-1]!=s[j*2-i-1]:
                cnt+=1
print(ans-cnt)
Buggy code:
n = int(input())
s = input()
ans = s.count('B') + s.count('G') + s.count('R')
for i in range(n):
  for j in range(i, n-1):
    k = 2*j - i
    if k >= n:
      continue
    if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
      ans -= 1

print(ans)

Fixed code:
n = int(input())
s = input()
ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n):
  for j in range(i, n-1):
    k = 2*j - i
    if k >= n:
      continue
    if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
      ans -= 1

print(ans)
Buggy code:
N = int(input())
S= input()
count = 0
R,G,B = [],[],[]
r = S.count('R')
g = S.count('G')
b = S.count('B') 
for i in range(N):
    for j in range(i+1,N+1):
        if S[i] != S[j] and S[2*j-i] != S[i] and S[2*j-i] != S[j]:
            sub += 1
ans = r*g*b -sub
print(ans)
       

Fixed code:
N = int(input())
S= input()
sub = 0
R,G,B = [],[],[]
r = S.count('R')
g = S.count('G')
b = S.count('B') 
for i in range(N):
    for j in range(i+1,N):
        if 2*j-i > N-1:
            break
        if S[i] != S[j] and S[2*j-i] != S[i] and S[2*j-i] != S[j]:
            sub += 1
ans = r*g*b -sub
print(ans)
Buggy code:
import collections

N=int(input())
S=input()

lenR=S.count("R")
lenG=S.count("G")
lenB=S.count("B")

count=0
for i in range(N-2):
    for j in range(i,N-1):
        if 2*j-i>N:
            continue
        if (S[i] != S[j]) and (S[i]!=S[2*j-i]) and (S[j]!=S[2*j-i]):
                    count+=1
    
print(lenR*lenG*lenB-count)

Fixed code:
import collections

N=int(input())
S=input()

lenR=S.count("R")
lenG=S.count("G")
lenB=S.count("B")

count=0
for i in range(N-2):
    for j in range(i,N-1):
        k=2*j-i
        if k>=N:
            continue
        else:
            if (S[i] != S[j]) and (S[i]!=S[k]) and (S[j]!=S[k]):
                count+=1
    
print(lenR*lenG*lenB-count)
Buggy code:
def main():
    import collections
    import sys
    sys.setrecursionlimit(50000)
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
    else:
        str_list=list(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
        list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
        list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
        list23=[]
        if RGB_list[2][0]==0 or RGB_list[1][0]==0:
            print(0)
        else:
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))
            print(sys.getrecursionlimit())

if __name__ == '__main__':
    main()


Fixed code:
def main():
    import collections
    import sys
    sys.setrecursionlimit(5000000)
    input = sys.stdin.readline
    N=int(input())
    S=input()
    if N<=3:
        print(0)
    else:
        str_list=list(S[:N])
        result=0
        c=collections.Counter(str_list)
        RGB_list=c.most_common()

        if len(c)<3:
            print(0)

        else:

            list1=[i for i, x in enumerate(str_list) if x == RGB_list[0][0]]
            list2=[i for i, x in enumerate(str_list) if x == RGB_list[1][0]]
            list3=[i for i, x in enumerate(str_list) if x == RGB_list[2][0]]
            list23=[]

        
            for i in list3:
                for j in list2:
                    list23+=[2*i-j,2*j-i,(i+j)/2]
            c1=collections.Counter(list23)
            for k in list1:
                for l in c1.keys():
                    if k==l:
                        result+=c1[l]
            print(int(RGB_list[0][1]*RGB_list[1][1]*RGB_list[2][1]-result))

if __name__ == '__main__':
    main()
Buggy code:
n=int(input())
s=input()
x=(s.count('R'))*(s.count('G'))*(s.count('B'))
for i in range(1,(n-1)//2):
  for j in range(n-i*2):
    if len(set([s[j],s[j+i],s[j+i+i]]))==3:
      x-=1
print(x)

Fixed code:
n=int(input())
s=input()
x=(s.count('R'))*(s.count('G'))*(s.count('B'))
for i in range(1,(n-1)//2+1):
  for j in range(n-i*2):
    if len(set([s[j],s[j+i],s[j+i+i]]))==3:
      x-=1
print(x)