qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import gcd, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
c = 0
K = INT()
ans = 0
 
for i in range(1, K + 1):
    for j in range(1, K + 1):
        a = gcd(i, j)
        for k in range(1, K + 1):
            b = gcd(a, k)
            ans += b
print(ans)            

Fixed code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import gcd, ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
# from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
 
K = INT()
 
ans = 0
for i in range(1, K + 1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            ans += gcd(gcd(i, j), k)
print(ans)
Buggy code:
import math

K = int(input())

Sum = []
for a in range(1, K+1):
    for b in range(1, K + 1):
        gcd2 = math.gcd(i.j)
        for c in range(1, K + 1):
            gcd = math.gcd(gcd2, c)
            Sum.append(gcd)

print(sum(Sum))


Fixed code:
import math

K = int(input())

Sum = []
for a in range(1, K+1):
    for b in range(1, K + 1):
        gcd2 = math.gcd(a, b)
        for c in range(1, K + 1):
            gcd = math.gcd(gcd2, c)
            Sum.append(gcd)

print(sum(Sum))
Buggy code:
from math import math

K = int(input())
cnt = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            cnt += gcd(gcd(i,j),k)
print(cnt)

Fixed code:
from math import gcd

K = int(input())
cnt = 0

for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            cnt += gcd(gcd(i,j),k)
print(cnt)
Buggy code:
def gcd(a, b):
    # `a >= b` is sopposed
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def main():
    K = 200
    gcd_memo = [[0 for _ in range(K + 1)] for _ in range(K + 1)]
    for a in range(1, K + 1):
        for b in range(a, K + 1):
            left, right = max([a, b]), min([a, b])
            gcd_ab = gcd(left, right)
            gcd_memo[a][b] = gcd_ab
            gcd_memo[b][a] = gcd_ab
    answer = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            gcd_ab = gcd_memo[a][b]
            answer += sum(gcd_memo[gcd_ab])
    print(answer)


if __name__ == '__main__':
    main()

Fixed code:
def gcd(a, b):
    # `a >= b` is sopposed
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


def main():
    K = int(input())
    gcd_memo = [[0 for _ in range(K + 1)] for _ in range(K + 1)]
    for a in range(1, K + 1):
        for b in range(a, K + 1):
            left, right = max([a, b]), min([a, b])
            gcd_ab = gcd(left, right)
            gcd_memo[a][b] = gcd_ab
            gcd_memo[b][a] = gcd_ab
    answer = 0
    for a in range(1, K + 1):
        for b in range(1, K + 1):
            gcd_ab = gcd_memo[a][b]
            answer += sum(gcd_memo[gcd_ab])
    print(answer)


if __name__ == '__main__':
    main()
Buggy code:
import math
from collections import Counter

K = int(input())

memo = {frozenset((i, j)): math.gcd(i, j) 
        for i in range(1, K+1) for j in range(i, K+1)}

counter = Counter([memo[frozenset((i, j))] 
                   for i in range(1, K+1) for j in range(1, K+1)])

total = 0
for i in range(1, K+1):
  for value, count = counter.items():
    total += memo[frozenset((i, value))] * count
    
print(total)

Fixed code:
import math
from collections import Counter

K = int(input())

memo = {frozenset((i, j)): math.gcd(i, j) 
        for i in range(1, K+1) for j in range(i, K+1)}

counter = Counter([memo[frozenset((i, j))] 
                   for i in range(1, K+1) for j in range(1, K+1)])

total = 0
for i in range(1, K+1):
  for value, count in counter.items():
    total += memo[frozenset((i, value))] * count
    
print(total)
Buggy code:
def gcd(a, b):
  if b > a:
    temp = b
    b = a
    a = temp
  if a % b == 0:
    return b
  else:
    return gcd(b, a % b)

def sum_of_gcd(k):
  ans = 0
  for i in range(1, k + 1):
    for j in range(1, k + 1):
      for k in range(1, k + 1):
        if i < j and j < k:
          ans += gcd(i, gcd(j, k)) * 6
        elif i < j and j == k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j == k:
          ans += gcd(i, gcd(j, k))
  return ans

n = int(input())
print(sum_of_gcd(n))

Fixed code:
def gcd(a, b):
  if b > a:
    temp = b
    b = a
    a = temp
  if a % b == 0:
    return b
  else:
    return gcd(b, a % b)
def sum_of_gcd(k):
  ans = 0
  for i in range(1, k + 1):
    for j in range(1, k + 1):
      for k in range(1, k + 1):
        if i < j and j < k:
          ans += gcd(i, gcd(j, k)) * 6
        elif i < j and j == k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j < k:
          ans += gcd(i, gcd(j, k)) * 3
        elif i == j and j == k:
          ans += gcd(i, gcd(j, k))
  return ans
 
n = int(input())
print(sum_of_gcd(n))
Buggy code:
k = int(input())

from functools import reduce
def gcd_list(numbers):
  return reduce(math.gcd, numbers)

total = 0
for i in range(1, k+1):
  for j in range(i, k+1):
    for k in range(j, k+1):
      if i == j and j == k and i == k:
        x = 1
      elif i != j and i != k and j != k:
        x = 6
      else:
        x = 3
        
      total += x * gcd_list([i, j, k])
print(total)

Fixed code:
from itertools import combinations
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)

n = int(input())

total = 0
for i in range(1, n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            if  i == j and j == k and i == k:
                x = 1
            elif i != j and j != k and i != k:
                x = 6
            else:
                x = 3
            
            total += x * gcd_list([i, j, k])
        
print(total)
Buggy code:
import math
from functools import reduce

def gcd(*numbers):
    r = reduce(math.gcd, numbers)
    return r

def main():
    K = int(input())
    g = 0
    for i in range(1, K+1, 1):
        for j in range(1, K+1, 1):
            g += gcd(i, j, i*j)         
    print(g)
main()


Fixed code:
from math import gcd
from functools import reduce

# def gcd(*numbers):
#     r = reduce(math.gcd, numbers)
#     return r

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

def gcd(a, b, c):
    g = gcd(a, b)
    return gcd(g, c)

K = int(input())
ans = 0

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

print(ans)


Fixed code:
from math import gcd

def gcd_3(a, b, c):
    g = gcd(a, b)
    return gcd(g, c)

K = int(input())
ans = 0

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

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

Fixed code:
a = int(input())
from math import gcd
b = 0
for i in range(1, a + 1):
  for j in range(1, a + 1):
    for k in range(1, a + 1):
      b += gcd(gcd(i, j), k)
      
print(b)
Buggy code:
mport math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


N=int(input())
S=0
T=0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        for k in range(j+1,N+1):
            S+=gcd(i,j,k)
for i in range(1,N+1):
    for j in range(i+1,N+1):
            T+=gcd(i,j,j)
            T+=gcd(i,j,j)
print(6*S+3*T+N*(N+1)//2)

Fixed code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)


N=int(input())
S=0
T=0
for i in range(1,N+1):
    for j in range(i+1,N+1):
        for k in range(j+1,N+1):
            S+=gcd(i,j,k)
for i in range(1,N+1):
    for j in range(i+1,N+1):
            T+=gcd(i,j,j)
            T+=gcd(i,j,j)
print(6*S+3*T+N*(N+1)//2)
Buggy code:
from functools import reduce
from itertools import product

def gcd(a, b):
    while b: a, b = b, a % b
    return a

def gcd_list(A): return reduce(gcd, A)

K = int(input())
S = K * (K + 1) // 2
for a, b in combinations(range(1, K+1), 2):
    S += 6 * gcd(a, b)
for a, b, c in combinations(range(1, K+1), 3):
    S += 6 * gcd_list((a, b, c))
print(S)

Fixed code:
from functools import reduce
from itertools import combinations

def gcd(a, b):
    while b: a, b = b, a % b
    return a

def gcd_list(A): return reduce(gcd, A)

K = int(input())
S = K * (K + 1) // 2
for a, b in combinations(range(1, K+1), 2):
    S += 6 * gcd(a, b)
for a, b, c in combinations(range(1, K+1), 3):
    S += 6 * gcd_list((a, b, c))
print(S)
Buggy code:
import math

n=int(input())

sum = 0

for i in range(n):
    for j in range(n):
        for k in range(n):
            sum += math.gcd(i,math.gcd(j,k))

print(sum)

Fixed code:
import math

n=int(input())

sum = 0

for i in range(1,n+1):
    for j in range(1,n+1):
        for k in range(1,n+1):
            sum += math.gcd(i,math.gcd(j,k))

print(sum)
Buggy code:
import math

n = int(input())
ans = [gcd(i+1, gcd(j+1, k+1)) for i in range(n) for j in range(n) for k in range(n)]
print(sum(ans))

Fixed code:
import math

n = int(input())
ans = [math.gcd(i+1, math.gcd(j+1, k+1)) for i in range(n) for j in range(n) for k in range(n)]
print(sum(ans))
Buggy code:
import math, itertools
from functools import reduce
def gcd_list(numbers):
    return(reduce(math.gcd,numbers))
k=int(input())
ans=0
for numbers in itertools.combinations_with_replacement(range(1,k+1),3):
    a,b,c=numbers
    if a==b==c:
        ans+=gcd_list(numbers)
    elif a!=b and a!=c:
        ans+=6*gcd_list(numbers)
    else:
        ans+=3*gcd_list(numbers)
print(ans)

Fixed code:
import math, itertools
from functools import reduce
def gcd_list(numbers):
    return(reduce(math.gcd,numbers))
k=int(input())
ans=0
for numbers in itertools.combinations_with_replacement(range(1,k+1),3):
    a,b,c=numbers
    if a==b==c:
        ans+=gcd_list(numbers)
    elif a!=b and a!=c and b!=c:
        ans+=6*gcd_list(numbers)
    else:
        ans+=3*gcd_list(numbers)
print(ans)
Buggy code:
from fractions import gcd
k=int(input())
ans=0
for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            ans+=gcd(i,gcd(j,l))
print(ans)

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

print(ans)
Buggy code:
from math import gcd

K = int(input())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        g = gcd(a,b)
        if g == 1:
            ans += K
        else:
            for c in range(1,K+1):
                ans += gcd(g,c)
                cnt += 1
print(ans)

Fixed code:
from math import gcd

K = int(input())
ans = 0
for a in range(1,K+1):
    for b in range(1,K+1):
        g = gcd(a,b)
        if g == 1:
            ans += K
        else:
            for c in range(1,K+1):
                ans += gcd(g,c)

print(ans)
Buggy code:
from fractions import gcd
K = int(input())

result = 0
for k in range(1, K + 1):
  for l in range(1, K + 1):
    for m in range(1, K + 1):
      gcd_res = gcd(gcd(k, l), m)
      result += gcd_res

print(result)


Fixed code:
from math import gcd
K = int(input())

result = 0
for k in range(1, K + 1):
  for l in range(1, K + 1):
    for m in range(1, K + 1):
      gcd_res = gcd(gcd(k, l), m)
      result += gcd_res

print(result)
Buggy code:
import itertools

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def gcd_3(a,b,c):
    a = gcd(gcd(a,b),c)
    return a

k = int(input())
ans = 0

num = list(itertools.combinations_with_replacement(range(1,k+1),3))
print(num)
for l in num:
    a,b,c = l
    if a==b==c:
        ans += a
    elif a!=b!=c:
        ans += gcd_3(a,b,c)*6
    else:
        ans += gcd_3(a,b,c)*3
print(ans)

Fixed code:
import itertools

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def gcd_3(a,b,c):
    a = gcd(gcd(a,b),c)
    return a

k = int(input())
ans = 0

num = list(itertools.combinations_with_replacement(range(1,k+1),3))

for l in num:
    a,b,c = l
    if a==b==c:
        ans += a
    elif a!=b!=c:
        ans += gcd_3(a,b,c)*6
    else:
        ans += gcd_3(a,b,c)*3
print(ans)
Buggy code:
import math

k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        a = gcd(i,j)
        for l in range(1,k+1):
            ans += gcd(a,l)

print(ans)

Fixed code:
import math

k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        a = math.gcd(i,j)
        for l in range(1,k+1):
            ans += math.gcd(a,l)

print(ans)
Buggy code:
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from math import gcd
from math import ceil, floor
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    ans = 0
    for a in range(1, n+1):
        for b in range(1, n+1):
            tmp = gcd(a, b)
            for c in range(1, n+1):
                ans += gcd(tmp, c)
    print(c)

if __name__ == '__main__':
    main()



Fixed code:
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations
from math import gcd
from math import ceil, floor
sys.setrecursionlimit(10 ** 6)

def input():
    return sys.stdin.readline()[:-1]

def main():
    n = int(input())
    ans = 0
    for a in range(1, n+1):
        for b in range(1, n+1):
            tmp = gcd(a, b)
            for c in range(1, n+1):
                ans += gcd(tmp, c)
    print(ans)

if __name__ == '__main__':
    main()
Buggy code:
import math

K = int(input())



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


print(apt(K))


Fixed code:
import math

K = int(input())
cnt = 0
for i in range(1, K+1):
    for j in range(1, K + 1):
        for k in range(1, K + 1):
            cnt += math.gcd(k, math.gcd(i, j))


print(cnt)
Buggy code:
K = int(input())

ans = 0

import math

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

print(ans)

Fixed code:
K = int(input())

ans = 0

import math

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

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

Fixed code:
k=int(input())
ans=0
from math import gcd
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      ans+=gcd(gcd(a,b),c)
print(ans)
Buggy code:
from Math import gcd

K = int(input())

result = 0
for a in range(1, K + 1):
  for b in range(1, K + 1):
    for c in range(1, K + 1):
      result += gcd(c, gcd(a, b))
      
print(result)

Fixed code:
from math import gcd
 
K = int(input())
 
result = 0
for a in range(1, K + 1):
  for b in range(1, K + 1):
    for c in range(1, K + 1):
      result += gcd(c, gcd(a, b))
      
print(result)
Buggy code:
# coding: utf-8
import math
from functools import reduce

K = int(input())
tmp = []

c = 0
for i in range(K):
    for j in range(K):
        tmp.append(math.gcd(i + 1, j + 1))
        c = c + 1

tmp2 = []
for k in tmp:
    for m in range(K):
        tmp2.append(math.gcd(k, m+1))

print("sum:",sum(tmp2))

Fixed code:
# coding: utf-8
import math
from functools import reduce

K = int(input())
tmp = []

c = 0
for i in range(K):
    for j in range(K):
        tmp.append(math.gcd(i + 1, j + 1))
        c = c + 1

tmp2 = []
for k in tmp:
    for m in range(K):
        tmp2.append(math.gcd(k, m+1))

print(sum(tmp2))
Buggy code:
import math

# input
K = int(input())

# process
gcdl = []
for i in range(K):
    l = []
    for j in range(K):
        l.append(math.gcd(i+1, j+1))
    gcdl.append(l)
print(gcdl)

ans = 0
for a in range(K):
    for b in range(a, K):
        for c in range(b, K):
            print([a, b, c])
            if a == c:
                ans += a+1
            elif b == c:
                ans += gcdl[a][b]*3
            elif a == b:
                ans += gcdl[a][c]*3
            else:
                t = gcdl[a][b]
                t = gcdl[t-1][c]
                ans += t*6

# output
print(ans)


Fixed code:
import math

# input
K = int(input())

# process
gcdl = []
for i in range(K):
    l = []
    for j in range(K):
        l.append(math.gcd(i+1, j+1))
    gcdl.append(l)
# print(gcdl)

ans = 0
for a in range(K):
    for b in range(a, K):
        for c in range(b, K):
            # print([a, b, c])
            if a == c:
                ans += a+1
            elif b == c:
                ans += gcdl[a][b]*3
            elif a == b:
                ans += gcdl[a][c]*3
            else:
                t = gcdl[a][b]
                t = gcdl[t-1][c]
                ans += t*6

# output
print(ans)
Buggy code:
import math
K = int(input())
for a in range(1, K+1):
    for b in range(1, K+1):
        tmp = math.gcd(a, b)
        cnt = sum([math.gcd(tmp, c) for c in range(1, K+1)])
print(cnt)

Fixed code:
import math
K = int(input())
tmp = 0
cnt = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        tmp = math.gcd(a, b)
        cnt += sum([math.gcd(tmp, c) for c in range(1, K+1)])
print(cnt)
Buggy code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


K = int(input())

ans = 0

for a in range(1, K+1):
    for b in range(1, K+1):
        gcd = gcd(a, b)
        for c in range(1, K+1):
            ans += gcd(gcd, c)

print(ans)

Fixed code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a


K = int(input())

ans = 0

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

print(ans)
Buggy code:
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m

K = int(input())
ans = 0
for a in range(1, K + 1):
    for b in range(a + 1, K + 1):
        for c in range(b + 1, K + 1):
            _ans = gcd(gcd(a, b), c)
            if a == b and b == c:
                ans += _ans
            elif a == b or b == c:
                ans += 3 * _ans
            else:
                ans += 6 * _ans
print(ans)


Fixed code:
def gcd(m, n):
    while n:
        m, n = n, m % n
    return m

K = int(input())
ans = 0
for a in range(1, K + 1):
    for b in range(a, K + 1):
        for c in range(b, K + 1):
            _ans = gcd(gcd(a, b), c)
            if a == b and b == c:
                ans += _ans
            elif a == b or b == c:
                ans += 3 * _ans
            else:
                ans += 6 * _ans
print(ans)
Buggy code:
n = int(input())
import fractions

ans = 0
for i in range(1,n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            if i == j and j == k:
                ans += i
            
            elif len({i,j,k}) == 2:
                ans += fractions.gcd(fractions.gcd(i,j),k)*3
            
            elif len({i,j,k}) == 3:
                ans += fractions.gcd(fractions.gcd(i,j),k)*6
        
print(ans)

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

ans = 0
for i in range(1,n+1):
    for j in range(i, n+1):
        for k in range(j, n+1):
            if i == j and j == k:
                ans += i
            
            elif len({i,j,k}) == 2:
                ans += math.gcd(math.gcd(i,j),k)*3
            
            elif len({i,j,k}) == 3:
                ans += math.gcd(math.gcd(i,j),k)*6
        
print(ans)
Buggy code:
import functools
from fractions import gcd
k = int(input())
cnt = 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:
                cnt += i
            elif i == j and j != l:
                li = [i,l]
                cnt += functools.reduce(gcd,li)*3
            elif i != j and j == l:
                li = [i,j]
                cnt += functools.reduce(gcd,li)*3
            else:
                li = [i,j,l]
                cnt += functools.reduce(gcd,li)*6
print(cnt)

Fixed code:
import functools
from math import gcd
k = int(input())
cnt = 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:
                cnt += i
            elif i == j and j != l:
                li = [i,l]
                cnt += functools.reduce(gcd,li)*3
            elif i != j and j == l:
                li = [i,j]
                cnt += functools.reduce(gcd,li)*3
            else:
                li = [i,j,l]
                cnt += functools.reduce(gcd,li)*6
print(cnt)
Buggy code:
import math
n = int(input())
ans = 0
for i in range(1,n):
  for j in range(1, n):
    for k in range(1, n):
      ans += math.gcd(i, math.gcd(j, k))
print(ans)

Fixed code:
K=int(input())

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

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

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

print(ans)


Fixed code:
import sys
from math import gcd
input = sys.stdin.readline

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

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

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):
        gcd_ij=gcd(i,j)
        for k in range(1,n+1):
            ans+=gcd(gcd_ij,k)
print(ans)
Buggy code:
import math
n = int(input())
lis = [[0] * n for i in range(n)]
for i in range(n):
  for j in range(n):
    lis[i][j] = math.gcd(i+1,j+1)
ans = 0
for i in range(n):
  for j in range(n):
    for k in range(n):
      ans += lis[i][lis[k][j]]
print(ans)

Fixed code:
import math
n = int(input())
lis = [[0] * n for i in range(n)]
for i in range(n):
  for j in range(n):
    lis[i][j] = math.gcd(i+1,j+1)
ans = 0
for i in range(n):
  for j in range(n):
    for k in range(n):
      ans += lis[i][lis[k][j]-1]
print(ans)