qyliang/CodeNanoFix huggingface dataset:
Buggy code:
k = int(input())
import math
k1 = 0
k2 = 0
k3 = 0
count = 0
for i in range(0,k):
  k1 = k1 + 1
  for j in range(0,i):
    k2 = k2 + 1
    for k in range(0, j):
      k3 = k3 + 1
      if k1==k2==k3:
        count = count + k1
      elif k1==k2 or k2==k3 or k3==k1:
        count = count + 3*math.gcd(k1,k2,k3)
      else:
        count = count + 6*math.gcd(k1,k2,k3)

Fixed code:
k = int(input())
import math
k1 = 0
k2 = 0
k3 = 0
count = 0
for i in range(0,k):
  k1 = k1 + 1
  k2 = 0
  for j in range(0,k1):
    k3=0
    k2 = k2 + 1
    for k in range(0, k2):
      k3 = k3 + 1
      if k1==k2==k3:
        count = count + k1
      elif k1==k2:
        count = count + 3*math.gcd(k1,k3)
      elif k2==k3:
        count = count + 3*math.gcd(k1,k2)
      elif k3==k1:
        count = count + 3*math.gcd(k1,k2)
      else:
        k4 = math.gcd(k1,k2)
        count = count + 6*math.gcd(k3,k4)
print(count)
Buggy code:
from math import *

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            ans += gcd(i, j, k)

print(ans)

Fixed code:
from math import *

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(tmp, k)

print(ans)
Buggy code:
import math
from functools import reduce
k=int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans=0
for i in range(1,k+1):
  for j in range(j,k+1):
    for l in range(l,k+1):
      if l==i:
        ans+=gcd(i,j,l)
      elif i==j or j==l:
        ans+=2*gcd(i,j,l)
      else:
        ans+=gcd(i,j,l)
print(ans)


Fixed code:
import math
from functools import reduce
k=int(input())
def gcd(*numbers):
    return reduce(math.gcd, numbers)
ans=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for l in range(j,k+1):
      if l==i:
        ans+=gcd(i,j,l)
      elif i==j or j==l:
        ans+=3*gcd(i,j,l)
      else:
        ans+=6*gcd(i,j,l)
print(ans)
Buggy code:
from math import gcd
K = int(iniput())
sum_gcd = [0]*201
ans = 0
 
for i in range(1,K+1):
  for j in range(1,K+1):
    sum_gcd[gcd(i,j)] += 1
for i in range(1,K+1):
  for k in range(1,K+1):
    ans += sum_gcd[i]*gcd(i,k)
 
print(ans)

Fixed code:
from math import gcd
K = int(input())
sum_gcd = [0]*201
ans = 0
 
for i in range(1,K+1):
  for j in range(1,K+1):
    sum_gcd[gcd(i,j)] += 1
for i in range(1,K+1):
  for k in range(1,K+1):
    ans += sum_gcd[i]*gcd(i,k)

print(ans)
Buggy code:
from fractions import gcd
k = int(input())
ans = 0
for h in range(1,k+1):
    for i in range(1, k+1):
        for j in range(1, k+1):
            ans += gcd(h, gcd(i, j))
print(ans)


Fixed code:
from math import gcd
k = int(input())
ans = 0
for h in range(1,k+1):
    for i in range(1, k+1):
        for j in range(1, k+1):
            ans += gcd(h, gcd(i, j))
print(ans)
Buggy code:
def main():
    k = int(input())
    k1 = k + 1

    sum = 0
    for i in range(1, k1):
        for j in range(1, k1):
            for m in range(1, k1):
                sum += math.gcd(math.gcd(i, j), m)
    print(sum)

main()

Fixed code:
import math


def main():
    k = int(input())
    k1 = k + 1

    sum = 0
    for i in range(1, k1):
        for j in range(1, k1):
            for m in range(1, k1):
                sum += math.gcd(math.gcd(i, j), m)
    print(sum)

main()
Buggy code:
K = int(input())
S = 0

def gcd(a,b):
   while b != 0:
       a, b = b, a % b
       if b ==0:
           return a
A1 = [0,0]
A2 = [0,0,0]
for i in range(1, K):
    S = S + i

if K > 1:
    for j in range(1, K):
        A1[0] =  j
        for k in range(j+1,K+1):
            A1[1] = k
            S += 6 * gcd(A1[1],A1[0])

if K > 2:
    for i1 in range(1, K-1):
        A2[0] = i1
        for k1 in range(i1+1, K):
            A2[1] = k1
            for j1 in range(k1+1,K+1):
                A2[2] = j1
                G3 = gcd(A2[2],A2[1])
                if G3 >= A2[0]:
                    S += 6 * gcd(G3,A2[0])
                else:
                    S += 6 * gcd(A2[0],G3)
                    
print(S)

Fixed code:
K = int(input())
S = 0

def gcd(a,b):
   while b != 0:
       a, b = b, a % b
       if b ==0:
           return a
A1 = [0,0]
A2 = [0,0,0]
for i in range(1, K+1):
    S = S + i

if K > 1:
    for j in range(1, K):
        A1[0] =  j
        for k in range(j+1,K+1):
            A1[1] = k
            S += 6 * gcd(A1[1],A1[0])

if K > 2:
    for i1 in range(1, K-1):
        A2[0] = i1
        for k1 in range(i1+1, K):
            A2[1] = k1
            for j1 in range(k1+1,K+1):
                A2[2] = j1
                G3 = gcd(A2[2],A2[1])
                if G3 >= A2[0]:
                    S += 6 * gcd(G3,A2[0])
                else:
                    S += 6 * gcd(A2[0],G3)
print(S)
Buggy code:
k = int(input())
s = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        ab = math.gcd(a, b)
        for c in range(1, k+1):
            s += math.gcd(ab, c)
print(s)


Fixed code:
import math

k = int(input())
s = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        ab = math.gcd(a, b)
        for c in range(1, k+1):
            s += math.gcd(ab, c)
print(s)
Buggy code:
import math

ans = 0
k = int(input())
for a in range(k):
    for b in range(k):
        tmp = math.gcd(a, b)
        for c in range(k):
            ans += math.gcd(tmp, c)

print(ans)


Fixed code:
import math

k = int(input())
ans = 0

for a in range(1, k+1):
    for b in range(1, k+1):
        tmp = math.gcd(a, b)
        for c in range(1, k+1):
            ans += math.gcd(tmp, c)

print(ans)
Buggy code:
import math
k = int(input())
ans = 0

for a in range(k):
    for b in range(k):
        d = math.gcd(a + 1, b + 1)
        for c in range(k):
            ans += math(d, c + 1)

print(ans)


Fixed code:
import math

k = int(input())
ans = 0
for a in range(1,k+1):
    for b in range(1,k+1):
        g = math.gcd(a,b)
        for c in range(1,k+1):
            ans += math.gcd(g,c)
print(ans)
Buggy code:
import math
N = int(input())
ans = (1+N)*N/2
for i in range(1,N+1):
  for j in range(1,i):
    ans += math.gcd(i,j)*3
for i in range(!,N+1):
  for j in range(1,i):
    if i== j:
      break
    for k in range(1,j):
      if i == k or j == k:
        break
      else:
        ans += math.gcd(i,j,k)*6
print(ans)

Fixed code:
import math
N = int(input())
ans = (1+N)*N/2
for i in range(1,N+1):
  for j in range(1,i):
    ans += math.gcd(i,j)*6
for i in range(1,N+1):
  for j in range(1,i):
    if i== j:
      break
    for k in range(1,j):
      if i == k or j == k:
        break
      else:
        ans += math.gcd(k,math.gcd(i,j))*6
print(int(ans))
Buggy code:
import math
K = int(input())
t = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            t += gcd(gcd(i,j),k)
print(t)

Fixed code:
from math import *
K = int(input())
t = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            t += gcd(gcd(i,j),k)
print(t)
Buggy code:
from math import gcd
k = int(input())
ans = 0

for s in range(1,k+1):
	for t in range(1,k+1):
  		for u in range(1, k+1):
			ans += gcd(gcd(s,t),u)
print(ans)

Fixed code:
from math import gcd
k = int(input())
ans = 0
 
for s in range(1,k+1):
  for t in range(1,k+1):
    for u in range(1, k+1):
      ans += gcd(gcd(s,t),u)
print(ans)
Buggy code:
from math import gcd
k = int(input())
ans = 0
for a in range(1,k+1):
  for b in range(a,k+1):
    ab = gcd(a,b)
    for c in range(c,k+1):
      g = gcd(ab,c)
      if a == b == c:
        ans += g
      elif a!=b!=c!=a:
        ans += g*6
      else:
        ans += g*3
print(ans)


Fixed code:
from math import gcd
k = int(input())
ans = 0
for a in range(1,k+1):
  for b in range(a,k+1):
    ab = gcd(a,b)
    for c in range(b,k+1):
      g = gcd(ab,c)
      if a == b == c:
        ans += g
      elif a != b !=c != a:
        ans += g*6
      else:
        ans += g*3
print(ans)
Buggy code:
import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [6, 3, 1]
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


def gcd(a, b, c):
    return math.gcd(math.gcd(a, b), c)


if __name__ == '__main__':
    s = time.time()
    main()
    print(time.time() - s)


Fixed code:
import sys
import math
import time
readline = sys.stdin.readline


def main():
    listSum = [1, 3, 6]
    k = int(input())
    sumGCD = 0
    for a in range(1, k + 1):
        for b in range(a, k + 1):
            for c in range(b, k + 1):
                sumGCD += gcd(a, b, c) * listSum[len(set([a, b, c])) - 1]
    print(sumGCD)


def gcd(a, b, c):
    return math.gcd(math.gcd(a, b), c)


if __name__ == '__main__':
    s = time.time()
    main()
    # print(time.time() - s)
Buggy code:
from itertools import combinations

def gcd(a, b):
    if a < b:
        tmp = a
        a = b
        b = tmp

    r = a % b
    while r!=0:
        a = b
        b = r
        r = a % b
    return b

def gcd_three(a, b, c):
    temp = gcd(a, b)
    return gcd(temp, c)

K = int(input())
ans = 0

ans += sum(range(1, K+1))

two_Ns = combinations(range(1, K+1), 2)
ans += 3*sum([gcd(*t) for t in two_Ns])

three_Ns = combinations(range(1, K+1), 3)
ans += 6*sum([gcd_three(*t) for t in three_Ns])

print(ans)

Fixed code:
from itertools import combinations

def gcd(a, b):
    if a < b:
        tmp = a
        a = b
        b = tmp

    r = a % b
    while r!=0:
        a = b
        b = r
        r = a % b
    return b

def gcd_three(a, b, c):
    temp = gcd(a, b)
    return gcd(temp, c)

K = int(input())
ans = 0

ans += sum(range(1, K+1))
ans += 6*sum([gcd(*t) for t in combinations(range(1, K+1), 2)])
ans += 6*sum([gcd_three(*t) for t in combinations(range(1, K+1), 3)])

print(ans)
Buggy code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    k = I()
    r = k * k
    for a in range(2, k+1):
        for b in range(1, k+1):
            g = fractions.gcd(a, b)
            if g == 1:
                r += k
                continue
            for c in range(1, k+1):
                r += fractions.gcd(g, c)

    return r


print(main())





Fixed code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import time,random

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)


def main():
    k = I()
    r = 0
    for a,b,c in itertools.product(range(1,k+1), repeat=3):
        r += math.gcd(math.gcd(a,b), c)

    return r


print(main())
Buggy code:
from math import gcd

n = int(input())
ans = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            ans += gcd(gcd(i, j), k)

Fixed code:
from math import gcd

n = int(input())
ans = 0
for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            ans += gcd(gcd(i, j), k)
            
print(ans)
Buggy code:
from math import gcd
k = int(input())
sum = 0
for a in range(1, k):
  for b in range(1, k):
    tmp = gcd(a,b)
    for c in range(1, k):
      sum += gcd(tmp, c)
print(sum)

Fixed code:
from math import gcd
k = int(input())
sum = 0
for a in range(1, k+1):
  for b in range(1, k+1):
    tmp = gcd(a,b)
    for c in range(1, k+1):
      sum += gcd(tmp, c)
print(sum)
Buggy code:
import math
K = int(input())
sum = 0
for i in range(1,K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      sum =+ math.gcd(k, math.gcd(i, j))
print(sum)


Fixed code:
from math import gcd
K = int(input())
sum = 0
for i in range(1,K+1):
  for j in range(1, K+1):
    for k in range(1, K+1):
      sum += gcd(k, gcd(i, j))
print(sum)
Buggy code:
import math
k=int(input())
ans=0

for i in range(1,k+1):
    for j in range(i,k+1):
        for l in range(j,k+1):
            if i==j and j==l:
                ans+=i
                
            elif i==j:
                ans+=3*math.gcd(i,l)
                
            else:
                ans+=6*math.gcd(math.gcd(i,j),l)
                
                
            
print(ans)

Fixed code:
import math
k=int(input())
ans=0

for i in range(1,k+1):
    for j in range(i,k+1):
        for l in range(j,k+1):
            if i==j and j==l:
                ans+=i
#                 print(i,j,l)
                
                
            elif i==j or j==l:
                ans+=3*math.gcd(i,l)
#                 print(i,j,l)
                
                
            else:
                ans+=6*math.gcd(math.gcd(i,j),l)
#                 print(i,j,l)
                
                
            
print(ans)
Buggy code:
import collections
N=int(input())
S=input()
lis=list(S)
C= collections.Counter(lis)
count=list(C.values())
c=0
for i in range(N):
    print(i)
    for j in range(i,(N+i-1) // 2+1):
        if(lis[i]!=lis[j]):
            if(lis[j]!=lis[2*j-i]):
                if(lis[i]!=lis[2*j-i]):
                    c+=1
print(count[0]*count[1]*count[2]-c)


Fixed code:
import collections
N=int(input())
S=input()
lis=list(S)
C= collections.Counter(lis)
count=list(C.values())
c=0
for i in range(N):
    for j in range(i,(N+i-1) // 2+1):
        if(lis[i]!=lis[j]):
            if(lis[j]!=lis[2*j-i]):
                if(lis[i]!=lis[2*j-i]):
                    c+=1
if(len(count)==3):
    print(count[0]*count[1]*count[2]-c)
else:
    print(0)
Buggy code:
from numba import jit

n=int(input())
s=input()
R=[]
G=[]
B=[]

@jit
def f():
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  r=len(R)
  g=len(G)
  b=len(B)
  if r==0 or g==0 or b==0:
    return 0
  else:
    ans=r*g*b
    m=0
    for j in range(1,n-1):
      for k in range(1,min(j,n-1-j)+1):
        lt=s[j-k]
        md=s[j]
        rt=s[j+k]
        if lt!=md and md!=rt and rt!=lt:
          m+=1
    return ans-m
print(f())

Fixed code:
n=int(input())
s=input()
R=[]
G=[]
B=[]
def f():
  for i in range(n):
    if s[i]=="R":
      R.append(i)
    elif s[i]=="G":
      G.append(i)
    else:
      B.append(i)
  r=len(R)
  g=len(G)
  b=len(B)
  if r==0 or g==0 or b==0:
    return 0
  else:
    ans=r*g*b
    m=0
    for j in range(1,n-1):
      for k in range(1,min(j,n-1-j)+1):
        lt=s[j-k]
        md=s[j]
        rt=s[j+k]
        if lt!=md and md!=rt and rt!=lt:
          m+=1
    return ans-m
print(f())
Buggy code:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    r = C.get("R")
    g = C.get("G")
    b = C.get("B")
    answer = r * g * b
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid * 2 - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    answer = -1
    print(answer)


if __name__ == "__main__":
    main()


Fixed code:
import sys
from collections import Counter


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    N = int(input())
    S = input()
    C = Counter(S)
    r = C.get("R",0)
    g = C.get("G",0)
    b = C.get("B",0)
    answer = r * g * b
    for left in range(N):
        for mid in range(left + 1, N):
            right = mid * 2 - left
            if right < N:
                if S[right] != S[mid] and S[mid] != S[left] and S[right] != S[left]:
                    answer -= 1
    print(answer)


if __name__ == "__main__":
    main()
Buggy code:
from sys import stdin
n = int(input())
s = stdin.readline()
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
count1 = r*g*b
count2 = 0
for i in range(0,n-3):
    for j in range(i+1,n-2):
        if 2*j-i<=n-1:
            if (s[i] != s[j])and(s[i] != s[2*j-i])and(s[j] != s[2*j-i]):
               count2 += 1
print(count1-count2)

Fixed code:
from sys import stdin
n = int(input())
s = stdin.readline()
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
count1 = r*g*b
count2 = 0
for i in range(0,n-2):
    for j in range(i+1,n-1):
        if 2*j-i<=n-1:
            if (s[i] != s[j])and(s[i] != s[2*j-i])and(s[j] != s[2*j-i]):
               count2 += 1
print(count1-count2)
Buggy code:
n = int(input().strip())
s = '_' + input().strip()
s += ''.join(['_'] * 10 ** 5)
r = []
g = []
b = []
for i in range(1, n + 1):
    if s[i] == 'R':
        r.append(i)
    elif s[i] == 'G':
        g.append(i)
    elif s[i] == 'B':
        b.append(i)

le = len(b)
ans = len(r) * len(g) * le
for x in r:
    for y in g:
        if (x + y) % 2 == 0 and s[(x + y) // 2] == 'B':
            ans -= 1
        if (1 <= (2 * x - y) and s[2 * x - y] == 'B') or (1 <= (2 * y - x) and s[2 * y - x] == 'B'):
            ans -= 1
print(ans)


Fixed code:
n = int(input().strip())
s = '_' + input().strip()
s += ''.join(['_'] * 10 ** 5)
r = []
g = []
b = []
for i in range(1, n + 1):
    if s[i] == 'R':
        r.append(i)
    elif s[i] == 'G':
        g.append(i)
    elif s[i] == 'B':
        b.append(i)

le = len(b)
ans = len(r) * len(g) * le
for x in r:
    for y in g:
        if (x + y) % 2 == 0 and s[(x + y) // 2] == 'B':
            ans -= 1
        if (1 <= (2 * x - y) and s[2 * x - y] == 'B'):
            ans -= 1
        if (1 <= (2 * y - x) and s[2 * y - x] == 'B'):
            ans -= 1
print(ans)
Buggy code:
n = int(input())
lis = str(input())
r = []
g = []
b = []
for i in range(n):
  if lis[i] == "R":
    r.append(i)
  elif lis[i] == "G":
    g.append(i)
  else:
    b.append(i)
ans = len(r) * len(g) * len(b)
for i in range(n-2):
  for j in range(i+1,n-1):
    k = j + (j-i)
    if (lis[i] != lis[j]) and (lis[j] != lis[k]) and (lis[k] != lis[i]):
      ans -= 1
print(ans)

Fixed code:
n = int(input())
lis = str(input())
r = []
g = []
b = []
for i in range(n):
  if lis[i] == "R":
    r.append(i)
  elif lis[i] == "G":
    g.append(i)
  else:
    b.append(i)
ans = len(r) * len(g) * len(b)
for i in range(1,n-1):
  for j in range(i+1,n):
    if i != j and 2 * j -i <= n:
      k = j + (j-i)
      if (lis[i-1] != lis[j-1]) and (lis[j-1] != lis[k-1]) and (lis[k-1] != lis[i-1]):
        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 d in range(n):
        j=i+d
        k=j+d
        if 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 d in range(n):
        j=i+d
        k=j+d
        if k>=n:
            break
        if s[i]!=s[j] and s[j]!=s[k] and s[k]!=s[i]:
            ans-=1

print(ans)
Buggy code:
N = int(input())
string = input()

result = string.count('R')*string.count('G')*string.count('B')

for i in range(N-2):
  for j in range(i+1, N):
    k = 2*j-1
    if k>=N:
      break
    if string[i] != string[j] != string[k]:
      result -= 1
print(result)

Fixed code:
N = int(input())
string = input()
 
result = string.count('R')*string.count('G')*string.count('B')
 
for i in range(N-2):
  for j in range(i+1, N-1):
    k = 2*j-i
    if k>=N:
      break
    if string[i] != string[j] and string[j] != string[k] and string[i] != string[k]:
      result -= 1
print(result)
Buggy code:
n = int(input())
s = input()

r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

discount = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        k = i + 2*(j-i)
        if k > n-1:
            break
        if s[i] == s[j] or s[i] == s[k] or s[j] == s[k]:
            discount += 1
print(r_count*g_count*b_count-discount)

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

r_count = s.count('R')
g_count = s.count('G')
b_count = s.count('B')

discount = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        k = i + 2*(j-i)
        if k > n-1:
            break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            discount += 1

print(r_count*g_count*b_count-discount)
Buggy code:
n = int(input())
s = input()

def im(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
R = im(s, "R")
G = im(s, "G")
B = im(s, "B")

ext = 0
if n >= 3:
    for i in range((n-3)//2):
        for j in range(n-(3+2*i)+1):
            if s[j] != s[j+i+1] and s[j] != s[j+2*(i+1)] and s[j+i+1] != s[j+2*(i+1)]:
                ext += 1

ans = len(R)*len(G)*len(B) - ext
print(ans)


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

def im(l, x):
    return [i for i, _x in enumerate(l) if _x == x]
R = im(s, "R")
G = im(s, "G")
B = im(s, "B")

ext = 0
if n >= 3:
    for i in range((n-3)//2+1):
        for j in range(n-(3+2*i)+1):
            if s[j] != s[j+i+1] and s[j] != s[j+2*(i+1)] and s[j+i+1] != s[j+2*(i+1)]:
                ext += 1

ans = len(R)*len(G)*len(B) - ext
print(ans)
Buggy code:
n, s = input().split(' ')
n = int(n)

r = s.count('R')
g = s.count('G')
b = s.count('B')

ans = r*g*b

for i in range(n):
  for j in range(i+1, n, 2):
    if s[i] != s[j] and s[i] != s[(i+j)/2] and s[(i+j)/2] != s[j]:
      count -= 1
print(count)

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 j in range(i+2, n, 2):
    if s[i] != s[j] and s[i] != s[int((i+j)/2)] and s[int((i+j)/2)] != s[j]:
      ans -= 1
print(ans)
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 j in range(i+1, n, 2):
    if s[i] != s[j] and s[i] != s[(i+j)/2] and s[(i+j)/2] != s[j]:
      count -= 1
print(count)

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-2):
    for j in range(1,n):
        if(i + (j*2) > n-1):
            break
        if(s[i] != s[i+j] and s[i] != s[i+j+j] and  s[i+j] != s[i+j+j]):
            ans -= 1
print(ans)