qyliang/CodeNanoFix huggingface dataset:
Buggy code:
k = int(input())
import math import gcd
ans = 0
for i in range(k+1):
    for j in range(k+1):
        n = math.gcd(i,j)
        for m in range(k+1):
            a = math.gcd(n,m)
            ans += a
print(ans)


Fixed code:
import math
a=int(input())
ans=0
for i in range(1,a+1):
    for j in range(1,a+1):
        for k in  range(1,a+1):
            ans+=math.gcd(i,math.gcd(j,k))
print(ans)
Buggy code:
from math import gcd
k = int(input())
ans = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        sub += gcd(i,j)
        for l in range(1,k+1):
            ans += gcd(sub,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):
        ans_=gcd(i,j)
        for l in range(1,k+1):
            ans+=gcd(ans_,l)
print(ans)
Buggy code:
from fractions import gcd

K = int(input())

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

Fixed code:
from math import gcd

K = int(input())

res = 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):
            res += gcd(tmp,k)
print(res)
Buggy code:
K = int(input())
def gcd(x, y):
  a, b = x, y
  while b != 0:
    a, b = b, a % b
  return a
gcds = [[0 for j in range(K)] for i in range(K)]
for i in range(K):
  for j in range(K):
    gcds[i][j] = gcd(i+1, j+1)
S = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      S += gcds[gcds[i][j]][k]
print(S)

Fixed code:
K = int(input())
def gcd(x, y):
  a, b = x, y
  while b != 0:
    a, b = b, a % b
  return a
gcds = [[0 for j in range(K)] for i in range(K)]
for i in range(K):
  for j in range(K):
    gcds[i][j] = gcd(i+1, j+1)
S = 0
for i in range(K):
  for j in range(K):
    for k in range(K):
      S += gcds[gcds[j][k]-1][i]
print(S)
Buggy code:
from math import gcd
K = int(input())

ans = 0

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

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):
        t = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(t, k)

print(ans)
Buggy code:
import math

K = int(input()) + 1
d = 0

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

Fixed code:
from math import gcd

K = int(input()) + 1
d = 0

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

Fixed code:
import math
N = int(input())
#sum_ = 1+N
sum_ = 0
for i in range(1, 1+N):
    for j in range(1, 1+N):
        a = math.gcd(i, j)
        for k in range(1, 1+N):
            sum_ += math.gcd(a, k)
            
print(sum_)
Buggy code:
import math
n = int(input() )

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

print( sum )

Fixed code:
import math
n = int(input() )
n+=1
sum = 0
for i in range (1,n):
    for j in range (1,n):
        gcdIJ = math.gcd(i,j)
        for k in range (1,n):
            sum += math.gcd( gcdIJ  ,k )
            #print(i,j,k)

print( sum )
Buggy code:
k = int(input())
ans = 0
import math
for i in range(1,k+1):
  for j in range(1,k+1):
    for l in range(1,k+1):
      f = gcd(i,j)
      ff = gcd(f,l)
      ans += ff
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):
    for l in range(1,k+1):
      f = math.gcd(i,j)
      ff = math.gcd(f,l)
      ans += ff
print(ans)
Buggy code:
def gcd(a, b):
    if a % b == 0:
        return b
    return gcd(b, a % b)


k = int(input())

sum = 0

# gcd(a,a,a)
sum += int((1+k)*k/2)

# gcd(a,b,b)
if k >= 2:
    for i in range(1, k+1):
        for j in range(1, k+1):
            sum += gcd(i, j)*3

# gcd(a,b,c)
if k >= 3:
    for i in range(1, k+1):
        for j in range(i+1, k+1):
            for l in range(j+1, k+1):
                sum += gcd(gcd(i, j), l)*6

print(sum)

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


k = int(input())

sum = 0

# gcd(a,a,a)
sum += int((1+k)*k/2)

# gcd(a,b,b)
if k >= 2:
    for i in range(1, k):
        for j in range(i+1, k+1):
            sum += gcd(i, j)*6

# gcd(a,b,c)
if k >= 3:
    for i in range(1, k-1):
        for j in range(i+1, k):
            for l in range(j+1, k+1):
                sum += gcd(gcd(i, j), l)*6

print(sum)
Buggy code:
n=int(input())
import math
ans=0
for i in range(2,n+1):
    for j in range(1,n+1):
        ij=math.gcd(i,j)
        if ij==1:
            ans+=n
        else:
            for k in range(1,n+1):
                ans+=math.gcd(ij,k)
print(ans)

Fixed code:
n=int(input())
import math
ans=0
for i in range(1,n+1):
    for j in range(1,n+1):
        ij=math.gcd(i,j)
        if ij==1:
            ans+=n
        else:
            for k in range(1,n+1):
                ans+=math.gcd(ij,k)
print(ans)
Buggy code:
import math
N = int(input())
GCD = [[math.gcd(i, j)-1 for i in range(1, N+1)] for j in range(1, N+1)]
#print(GCD)
all_gcd = [GCD[GCD[i][j]][m] for i in range(N) for j in range(N) for m in range(N)]
print(sum(all_gcd))

Fixed code:
import math
N = int(input())
GCD = [[math.gcd(i, j) for i in range(1, N+1)] for j in range(1, N+1)]
#print(GCD)
all_gcd = [GCD[GCD[i][j]-1][m] for i in range(N) for j in range(N) for m in range(N)]
print(sum(all_gcd))
Buggy code:
import math
N = int(input())
GCD = [[math.gcd(i, j) for i in range(1, 10)] for j in range(1, 10)]
all_gcd = [GCD[GCD[i][j]][m] for i in range(1, N+1) for j in range(1, N+1) for m in range(1, N+1)]
print(sum(all_gcd))


Fixed code:
import math
N = int(input())
all_gcd = [math.gcd(math.gcd(i, j), m) for i in range(1, N+1) for j in range(1, N+1) for m in range(1, N+1)]
print(sum(all_gcd))
Buggy code:
import math
from functools import reduce
from itertools import product
K=int(input())
gcd=0.
K=range(K)
for i,j,k in product(K,K,K):
            gcd+=reduce(math.gcd,(i+1,j+1,k+1))
print(gcd) 


Fixed code:
import math
from functools import reduce
from itertools import product
K=int(input())
gcd=0.
for i in range(K):
    for j in range(K):
        a=math.gcd(i+1,j+1)
        for k in range(K):
            gcd+=math.gcd(a,k+1)
print(int(gcd))
Buggy code:
import math
K = int(input())
S = 0
for i in range(K+1):
  for j in range(K+1):
    for l in range(K+1):
      S = math.gcd(l, math.gcd(j,i))
      
print(S)

Fixed code:
import math
K = int(input())
S = 0
for i in range(1,K+1):
  for j in range(1,K+1):
    for l in range(1,K+1):
      S = S + math.gcd(l, math.gcd(j,i))

print(S)
Buggy code:
s = input().split()
k = int(s[0])
n = 3
ans={}
for i in reversed(range(1, k+1)):
    # print(i*(math.floor(k/i))**n)
    ans[i]=math.floor(k/i)**n
    l=2
    j=i*l
    while j<=k:
        ans[i]=ans[i]-ans[j]
        l +=1
        j = i*l
res=0
for i in ans:
    res+=i*ans[i]
print(res)

Fixed code:
import math
s = input()
k = int(s)
n = 3
ans={}
for i in reversed(range(1, k+1)):
    ans[i]=math.floor(k/i)**n
    l=2
    j=i*l
    while j<=k:
        ans[i]=ans[i]-ans[j]
        l +=1
        j = i*l
res=0
for i in ans:
    res+=i*ans[i]
print(res)
Buggy code:
from fractions import gcd
K = int(input())
sum = 0

for a in range(1, K + 1):
    for b in range(1, K + 1):
        for c in range(1, K + 1):
            sum += gcd(a, gcd(b, 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):
        for c in range(1, K + 1):
            sum += gcd(a, gcd(b, c))

print(sum)
Buggy code:
from fractions import gcd

def main():
    n = int(input())

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

    print(t)

if __name__ == "__main__":
    main()

Fixed code:
from math import gcd

def main():
    n = int(input())

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

    print(t)

if __name__ == "__main__":
    main()
Buggy code:
import functools
from fractions import gcd
n = int(input())
@functools.lru_cache(None)
def main(n):
  g=0
  for i in range (1, n+1):
    for j in range (1, n+1):
      for k in range (1, n+1):
        g  += gcd(gcd(i,j),k)
  return (g)
print(main(n))

Fixed code:
import functools
from math import gcd
n = int(input())
@functools.lru_cache(None)
def main(n):
  g=0
  for i in range (1, n+1):
    for j in range (1, n+1):
      for k in range (1, n+1):
        g  += gcd(gcd(i,j),k)
  return (g)
print(main(n))
Buggy code:
from fractions import gcd
n = int(input())
g = 0
for i in range (1, n+1):
  for j in range (1, n+1):
    for k in range (1, n+1):
      g  += gcd(gcd(i,j),k)
print(g)



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

answer=0
for i in range(K):
  for j in range(K):
    gcd_ij=math.gcd(i,j)    
    for k in range(K):
      gcd_ijk=math.gcd(gcd_ij,k)
      answer+=gcd_ijk

print(answer)

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

answer=0
for i in range(1,K+1):
  for j in range(1,K+1):
    gcd_ij=math.gcd(i,j)    
    for k in range(1,K+1):
      gcd_ijk=math.gcd(gcd_ij,k)
      answer+=gcd_ijk
print(answer)
Buggy code:
from math import gcd
from itertools import permutations

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):
            dup = len(set([i, j, l]))
            if dup == 1:
                num = 1
            elif dup == 2:
                num = len(list(permutations([i, j, l]))) / 2
            else:
                num = len(list(permutations([i, j, l])))
            ans += gcd(i, gcd(j, l)) * num

print(ans)


Fixed code:
from math import gcd
from itertools import permutations

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):
            dup = len(set([i, j, l]))
            if dup == 1:
                num = 1
            elif dup == 2:
                num = len(list(permutations([i, j, l]))) / 2
            else:
                num = len(list(permutations([i, j, l])))
            ans += gcd(i, gcd(j, l)) * num

print(int(ans))
Buggy code:
import math
k = int(input())
sum =0
for a in range(1, k+1):
     for b in range(1, k+1):
         x = gcd(a, b)
         for c in range(1, k+1):
             sum += gcd(x, 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):
         x = gcd(a, b)
         for c in range(1, k+1):
             sum += gcd(x, c)
print(sum)
Buggy code:
import math
 
k = int(input())
sum = 0
 
for a in range(k - 2):
  for b in range(a + 1, k - 1):
    for c in range(b + 1, k):
      sum += 6 * math.gcd(a + 1, math.gcd(b + 1, c + 1))
      
for a in range(k - 1):
  for b in range(a + 1, k):
    sum += 3 * math.gcd(a + 1, b + 1)
    
sum += k * (k + 1) // 2
      
print(sum)

Fixed code:
import math
 
k = int(input())
sum = 0
 
for a in range(k - 2):
  for b in range(a + 1, k - 1):
    for c in range(b + 1, k):
      sum += 6 * math.gcd(a + 1, math.gcd(b + 1, c + 1))
      
for a in range(k - 1):
  for b in range(a + 1, k):
    sum += 6 * math.gcd(a + 1, b + 1)
    
sum += k * (k + 1) // 2
      
print(sum)
Buggy code:
import math

k = int(input())
sum = 0

for a in range(k):
  for b in range(k):
    for c in range(k):
      sum += math.gcd(a, math.gcd(b, c))
      
print(sum)

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


def better_gcd(a,b,c):
    tup = set((a,b,c))
    kinds = len(tup)
    if kinds == 3:
        return math.gcd(a, math.gcd(b, c)) * 6
    elif kinds == 2:
        return math.gcd(*tup) * 3
    else:
        return a

ans = 0
cands = list(itertools.combinations_with_replacement(range(200), 3))
for c in cands:
    ans += better_gcd(*c)
print(ans)

Fixed code:
K = int(input())
# K = 2
import math
import itertools

def better_gcd(a,b,c):
    tup = set((a,b,c))
    kinds = len(tup)
    if kinds == 3:
        return math.gcd(a, math.gcd(b, c)) * 6
    elif kinds == 2:
        return math.gcd(*tup) * 3
    else:
        return a

ans = 0
cands = list(itertools.combinations_with_replacement(range(1,K+1), 3))
for c in cands:
    ans += better_gcd(*c)
print(ans)
Buggy code:
from math import gcd
from itertools import combinations

def main():
    k = int(input())
    res = 0
    memo = [[0 for _ in range(k)] for _ in range(k)]
    for i in range(1, k+1):
        for j in range(i, k+1):
            tmp = gcd(i,j)
            memo[i][j] = tmp
            memo[j][i] = tmp

    for i in range(1, k+1):
        res += i 

    for c in combinations(range(1,k+1),2):
        ab = memo[c[0], c[1]]
        res += ab * 6

    for c in combinations(range(1,k+1), 3):
        ab = memo[c[0], c[1]]
        abc = memo[ab, c[2]]
        res += abc * 6
    print(res)


if __name__ == '__main__':
    main()



Fixed code:
import math
from itertools import combinations

def main():
    k = int(input())
    res = 0
    memo = [[0 for _ in range(k+1)] for _ in range(k+1)]
    for i in range(1, k+1):
        for j in range(i, k+1):
            tmp = math.gcd(i,j)
            memo[i][j] = tmp
            memo[j][i] = tmp

    for i in range(1, k+1):
        res += i 

    for c in combinations(range(1,k+1),2):
        ab = memo[c[0]][c[1]]
        res += ab * 6

    for c in combinations(range(1,k+1), 3):
        ab = memo[c[0]][c[1]]
        abc = memo[ab][c[2]]
        res += abc * 6
    print(res)


if __name__ == '__main__':
    main()
Buggy code:
import fractions
 
k = int(input())
ans = 0
 
for a in range(1, k+1):
    for b in range(1, k+1):
        tmp = fractions.gcd(a, b)
        for c in range(1, k+1):
            ans += fractions.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:
N = int(input())
sum=0
import math
for i in range(N):
  for j in range(N):
       t=gcd(i+1,j+1)
       for k in range(N):
          sum =sum + gcd(t, k+1)
print(sum)


Fixed code:
N = int(input())
sum=0
import math
for i in range(N):
  for j in range(N):
       t=math.gcd(i+1,j+1)
       for k in range(N):
          sum =sum + math.gcd(t, k+1)
print(sum)
Buggy code:
from math import gcd
k=int(input())
ans=0
for i in range(0,k):
  for j in range(0,k):
    for l in range(0,k):
      ans=ans+gcd(gcd(i,j),l)
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):
    GCD = gcd(i, j)
    for l in range(1, k+1):
      ans += gcd(GCD, l)
print(ans)
Buggy code:
import fractions
import sys
readline = sys.stdin.buffer.readline
s =int(readline().rstrip().decode())
def gcdsp(x,y,z):
    t =fractions.gcd(x,y)
    return fractions.gcd(t,z)
res = 0
for i in range(s):
    for j  in range(s):
        for k  in range(s):
            if i < j and j <= k:
                res += gcdsp(i+1, j+1, k+1)
res1 = int((s + 1)*s/2)
print(6*res+res1)


Fixed code:
import math
import sys
readline = sys.stdin.buffer.readline
s =int(readline().rstrip().decode())
def gcdsp(x,y,z):
    t =math.gcd(x,y)
    return math.gcd(t,z)
res = 0
for i in range(s):
    for j  in range(s):
        for k  in range(s):
            if i < j and j <= k:
                res += gcdsp(i+1, j+1, k+1)
res1 = int((s + 1)*s/2)
print(6*res+res1)
Buggy code:
from fractions import gcd

K = int(input())

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

print(res)

Fixed code:
from math import gcd

K = int(input())

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

print(res)
Buggy code:
import sys
import os
import fractions
import itertools

def file_input():
    f = open('Beginner_Contest_162/input.txt', 'r')
    sys.stdin = f

def main():
    #file_input()
    K=int(input())
    # map(int, input().split())
    sum=0

    combi_l = itertools.combinations_with_replacement(range(1,K+1),3)
    # print(combi_l)

    for combi in combi_l:
        # print(combi)
        if combi[0]==combi[1]==combi[2]:
            sum+=fractions.gcd(fractions.gcd(combi[0],combi[1]),combi[2])
        elif combi[0]==combi[1] or combi[1]==combi[2] or combi[2]==combi[0]:
            sum+=3*fractions.gcd(fractions.gcd(combi[0],combi[1]),combi[2])
        else:
            sum+=6*fractions.gcd(fractions.gcd(combi[0],combi[1]),combi[2])

    # for a in range(1,K+1):
    #     for b in range(1,K+1):
    #         tmp=fractions.gcd(a,b)
    #         for c in range(1,K+1):
    #             sum+=fractions.gcd(tmp,c)

    print(sum)

if __name__ == '__main__':
    main()


Fixed code:
import sys
import os
import itertools

def file_input():
    f = open('Beginner_Contest_162/input.txt', 'r')
    sys.stdin = f

def gcd(a,b):
    if b==0: return a
    else: return gcd(b,a%b)

def main():
    #file_input()
    K=int(input())
    # map(int, input().split())
    sum=0

    combi_l = itertools.combinations_with_replacement(range(1,K+1),3)
    # print(combi_l)

    for combi in combi_l:
        # print(combi)
        if combi[0]==combi[1]==combi[2]:
            sum+=gcd(gcd(combi[0],combi[1]),combi[2])
        elif combi[0]==combi[1] or combi[1]==combi[2] or combi[2]==combi[0]:
            sum+=3*gcd(gcd(combi[0],combi[1]),combi[2])
        else:
            sum+=6*gcd(gcd(combi[0],combi[1]),combi[2])

    # for a in range(1,K+1):
    #     for b in range(1,K+1):
    #         tmp=fractions.gcd(a,b)
    #         for c in range(1,K+1):
    #             sum+=fractions.gcd(tmp,c)

    print(sum)

if __name__ == '__main__':
    main()
Buggy code:
k=int(input())
ans=0
from fractions import gcd
for a in range(1,k+1):
    for b in range(1,k+1):
        t=gcd(a,b)
        for c in range(1,k+1):
            ans+=gcd(c,t)
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):
        t=gcd(a,b)
        for c in range(1,k+1):
            ans+=gcd(c,t)
print(ans)
Buggy code:
import math

k = int(input())
ans = 0
for a in range(1, k+1):
    for b in range(1, k+1):
        ab = math.gcd(a, b)
        if ab == 1:
            ans += k
            continue
    for k in range(1, k+1):
        ans += math.gcd(ab,k)

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):
        ab = math.gcd(a, b)
        if ab == 1:
            ans += k
            continue
        for c in range(1, k+1):
            ans += math.gcd(ab,c)

print(ans)
Buggy code:
def u(a,b):
  if(a<b):
    z = b
    b = a
    a = z
   r = a % b;
  while(r!=0):
    a = b
    b = r
    r = a % b
  return b

l = int(input())
s = 0
for i in range(1,l+1):
  for i2 in range(1,l+1):
    z = u(i,i2)
    for i3 in range(1,l+1):
      z2 = u(z,i3)
      s+=z2
print (s)

Fixed code:
def u(a,b):
  if(a<b):
    z = b
    b = a
    a = z
  r = a % b
  while(r!=0):
    a = b
    b = r
    r = a % b
  return b
 
l = int(input())
s = 0
for i in range(1,l+1):
  for i2 in range(1,l+1):
    z = u(i,i2)
    for i3 in range(1,l+1):
      z2 = u(i3,z)
      s+=z2
print (s)
Buggy code:
import math

K = int(input())
sum = 0

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

Fixed code:
import math

K = int(input())
sum = 0

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):
      sum += math.gcd(tmp, k)
      
print(sum)
Buggy code:
import math

K = int(input())
sum = 0

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


Fixed code:
import math
K = int(input())
rst = 0
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):
            rst += math.gcd(tmp, k)
print(rst)
Buggy code:
#c
import math
k=int(input())
sum(math.gcd(math.gcd(a,b),c) for a in range(1,k+1)for b in range(1,k+1)for c in range(1,k+1))

Fixed code:
#c
import math
k=int(input())
print( sum(math.gcd(math.gcd(a,b),c) for a in range(1,k+1)for b in range(1,k+1)for c in range(1,k+1)) )
Buggy code:
from fractions import gcd
k = int(input())
ans = 0
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)

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):
		for c in range(1,k+1):
			ans += gcd(gcd(a,b),c)

print(ans)
Buggy code:
N = int(input())
 
ans = 0
for a in range(1, N + 1):
    for b in range(1, N + 1):
        tmp = math.gcd(a, b)
        for c in range(1, N + 1):
            ans += math.gcd(tmp, c)
 
print(ans)

Fixed code:
import math

N = int(input())
 
ans = 0
for a in range(1, N + 1):
    for b in range(1, N + 1):
        tmp = math.gcd(a, b)
        for c in range(1, N + 1):
            ans += math.gcd(tmp, c)
print(ans)
Buggy code:
import math

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

K = int(input())

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

print(ans)

Fixed code:
import math

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

K = int(input())

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

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

sum = 0
for i in range(1,K+1):
	for j in range(1,K+1):
		temp = math.gcd(i,j)
		for m in range(1,K+1):
			sum = sum + math.gcv(temp,m)

print(sum)

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

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

print(sum)
Buggy code:
import math

K=int(input())
r=0

for i in range(1,K+1):
  for j in range(1,K+1):
    a=math.gcd(i,j)
    for k in range(K+1):
      b=math.gcd(a,k)
      r+=b
print(r)

Fixed code:
import math

K=int(input())
r=0

for i in range(1,K+1):
  for j in range(1,K+1):
    a=math.gcd(i,j)
    for k in range(1,K+1):
      b=math.gcd(a,k)
      r+=b
print(r)
Buggy code:
from math import gcd

n = int(input())
sum = 0
for i in range(1, n + 1):
    for j in range(1, i):
        for k in range(1, j):
            sum+=6*gcd(gcd(k,j),i)
        sum+=3*gcd(j,i)
    sum+=i
print(sum)

Fixed code:
from math import gcd

n = int(input())
sum = 0
for i in range(1, n + 1):
    for j in range(1, i):
        for k in range(1, j):
            sum += 6 * gcd(gcd(k, j), i)
        sum += 6 * gcd(j, i)
    sum += i
print(sum)