qyliang/CodeNanoFix huggingface dataset:
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):
      t_gcd=gcd(i,j)
      ans+=gcd(t_gcd,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):
      t_gcd=gcd(i,j)
      ans+=gcd(t_gcd,l)

print(ans)
Buggy code:
k=int(input())

import math
 
res=0
 
for n in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):

            res+=math.gcd(gcd(n,i),j)

print(res)

Fixed code:
k=int(input())

from math import gcd
 
res=0
 
for n in range(1,k+1):
    for i in range(1,k+1):
        for j in range(1,k+1):

            res+=gcd(gcd(n,i),j)

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

print(ans)
Buggy code:
import scipy as sp
import numpy as np
import math


N = int(input())

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

            ans += math.gcd(c, d)

print(ans)

Fixed code:
import scipy as sp
import numpy as np
import math


N = int(input())

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

            ans += math.gcd(c, d)

print(ans)
Buggy code:
import math
from itertools import product
from functools import reduce

def main():
    def gcd(numbers): return reduce(math.gcd, numbers)
    K = int(input())
    ans = 0
    valiation = list(itertools.product(range(1, K+1), repeat=3))
    for v in valiation:
        ans += gcd(v)
#     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)
        
    
if __name__ == '__main__':
    main()

Fixed code:
import math
# from itertools import product
from functools import reduce

def main():
#     def gcd(*numbers): return reduce(math.gcd, numbers)
    K = int(input())
    ans = 0
#     valiation = list(itertools.product(range(1, K+1), repeat=3))
#     for v in valiation:
#         ans += gcd(v)
    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)
        
    
if __name__ == '__main__':
    main()
Buggy code:
from math import gcd
k=200
ans=0
for i in range(1,k+1):
    for j in range(i,k+1):
        for k in range(j,k+1):
            s=len(set([i,j,k]))
            if s==1:
                p=1
            elif s==2:
                p=3
            elif s==3:
                p=6
            tmp=gcd(i,j)
            tmp= p*gcd(tmp,k)
            ans+=tmp
print(ans)

Fixed code:
from math import gcd
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):
            s=len(set([i,j,k]))
            if s==1:
                p=1
            elif s==2:
                p=3
            elif s==3:
                p=6
            tmp=gcd(i,j)
            tmp= p*gcd(tmp,k)
            ans+=tmp
print(ans)
Buggy code:
k = int(input())

import math
ans = sum(list(range(k+1)))
ans1 = 0
ans2 = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        ans1 += math.gcd(i,j)

ans = ans + ans1*3

for i in range(1,K+1):
    for j in range(1,i):
        for l in range(1,l):
            ans2 += math.gcd(math.gcd(i,j),l)

ans += ans2*6
print(ans)

Fixed code:
k = int(input())

import math
ans = 0
ans1 = 0
ans2 = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        ans1 += math.gcd(i,j)

ans = ans + ans1*3

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

ans += ans2*6
print(ans-sum(list(range(k+1)))*2)
Buggy code:
import math
k=int(input())
list=[]
for a in range(1,k+1):
  for b in range(1,k+1):
    for c in range(1,k+1):
      list.append(math.gcd((a,b),c))
print(sum(list))

Fixed code:
import math
k=int(input())
list=[]
for a in range(1,k+1):
  for b in range(1,k+1):
    t=math.gcd(a,b)
    for c in range(1,k+1):
      list.append(math.gcd(t,c))
print(sum(list))
Buggy code:
n = input()
total = 0

#a > b
def gcd(a,b):
	if b == 0:
		return a

	return gcd(b, a % b)

total = total + n * (n+1) / 2

for i in range(n):
	for j in range(i+1,n):
		total = total + 6 * gcd(j+1,i+1)

for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			l = gcd(j+1,k+1)
			if i < l:
				total = total + 6 * gcd(l,i+1)
			else:
				total = total + 6 * gcd(i+1,l)

print(int(total))

Fixed code:
n = int(input())
total = 0

#a > b
def gcd(a,b):
	if b == 0:
		return a

	return gcd(b, a % b)

total = total + n * (n+1) / 2

for i in range(n):
	for j in range(i+1,n):
		total = total + 6 * gcd(j+1,i+1)

for i in range(n):
	for j in range(i+1,n):
		for k in range(j+1,n):
			l = gcd(j+1,k+1)
			if i < l:
				total = total + 6 * gcd(l,i+1)
			else:
				total = total + 6 * gcd(i+1,l)

print(int(total))
Buggy code:
import fractions as f 
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):
   b=f.gcd(i,j)
   ans+=f.gcd(b,k)
print(ans)

Fixed code:
import math as f 
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):
   b=f.gcd(i,j)
   ans+=f.gcd(b,k)
print(ans)
Buggy code:
from math import gcd

k = int(input())
ans = 0

for a in range(k+1):
  for b in range(k+1):
    for c in range(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:
import math
from functools import reduce


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

n=int(input())
l1=range(1,n+1)
l2=range(1,n+1)
l3=range(1,n+1)

count=0

for i in l1:
    for j in l2:
        te=gcd(i,j)
        for k in l3:
            count+=(te,k)

print(count)

Fixed code:
import math
from functools import reduce


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

n=int(input())
l1=range(1,n+1)
l2=range(1,n+1)
l3=range(1,n+1)

count=0

for i in l1:
    for j in l2:
        te=math.gcd(i,j)
        for k in l3:
            count+=math.gcd(te,k)

print(count)
Buggy code:
import math
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)

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
N = int(input())
ans = sum([gcd(gcd(i,j),k) for i in range(N+1) for j in range(N+1) for k in range(N+1)])
print(ans)


Fixed code:
from math import gcd
N = int(input())
ans = sum([gcd(gcd(i,j),k) for i in range(1,N+1) for j in range(1,N+1) for k in range(1,N+1)])
print(ans)
Buggy code:
import gcd from math
def main(): #startline-------------------------------------------
    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)
if __name__ == "__main__":
    main() #endline===============================================

Fixed code:
from math import gcd
def main(): #startline-------------------------------------------
    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)
if __name__ == "__main__":
    main() #endline===============================================
Buggy code:
from math import gcd
k = int(input())+1
n = 0
for i in range(1,k):
  for j in range(i,k):
    for l in range(j, k):
      if i == j == l:
        print([i, j, l])
        print(gcd(i,gcd(j,l)))
        n += gcd(i,gcd(j,l))
      elif i == j or j == l or l == i:
        print([i,j,l])
        print(gcd(i,gcd(j,l))*3)
        n += gcd(i,gcd(j,l))*3
      else:
        print([i,j,l])
        print(gcd(i,gcd(j,l))*6)
        n += gcd(i,gcd(j,l))*6
print(n)

Fixed code:
from math import gcd
k = int(input())+1
n = 0
for i in range(1,k):
  for j in range(i,k):
    for l in range(j, k):
      if i == j == l:
        n += gcd(i,gcd(j,l))
      elif i == j or j == l or l == i:
        n += gcd(i,gcd(j,l))*3
      else:
        n += gcd(i,gcd(j,l))*6
print(n)
Buggy code:
k=int(input())
import fractions
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=fractions.gcd(i,j)
      c=fractions.gcd(d,k)
      if i!=j and j!=k and k!=i:
        x+=6*c
      elif (i!=j and j==k) or (j!=k and k==i) or (k!=i and i==j):
        x+=3*c
      else:
        x+=c
print(x)

Fixed code:
k=int(input())
import math
x=0
c=0
d=0
for i in range(1,k+1):
  for j in range(i,k+1):
    for k in range(j,k+1):
      d=math.gcd(i,j)
      c=math.gcd(d,k)
      if i!=j and j!=k:
        x+=6*c
      elif i==j==k:
        x+=c
      else:
        x+=3*c
print(x)
Buggy code:
import math
import itertools
GCD_over_150=[4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692]

N=int(input())
if N<150:
    GCD=[]
    GCD1=[]
    for i in range (1,N+1):
	    GCD.append(i)
    for i in itertools.product(GCD,repeat=3):
		GCD1.append(math.gcd(math.gcd(i[0],i[1]),i[2]))
	print(sum(GCD1))    
else:
    print(GCD_over_150[N-150])

Fixed code:
import math
import itertools
GCD_over_150=[4548003,4616104,4718640,4812789,4918561,5003286,5131848,5205481,5299011,5392008,5521384,5610705,5739009,5818390,5930196,6052893,6156139,6239472,6402720,6493681,6623853,6741078,6864016,6953457,7094451,7215016,7359936,7475145,7593865,7689630,7886244,7984165,8130747,8253888,8403448,8523897,8684853,8802826,8949612,9105537,9267595,9376656,9574704,9686065,9827097,9997134,10174780,10290813,10493367,10611772,10813692]
 
N=int(input())
if N<150:
	GCD=[]
	GCD1=[]
	for i in range (1,N+1):
		GCD.append(i)
	for i in itertools.product(GCD,repeat=3):
		GCD1.append(math.gcd(math.gcd(i[0],i[1]),i[2]))
	print(sum(GCD1))    
else:
    print(GCD_over_150[N-150])
Buggy code:
from math import gcd
K = int(input())
sumval = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            g = math.gcd(math.gcd(a,b),c)
            sumval += g
print(sumval)

Fixed code:
import math
K = int(input())
sumval = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        f = math.gcd(a,b)
        for c in range(1, K+1):
            g = math.gcd(f,c)
            sumval += g
print(sumval)
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):
    for t in range(1, k + 1):
      ans += gcd(gcd(i, j), 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):
        for m in range(1,k+1):
            ans+=gcd(i,gcd(j,m))
print(ans)
Buggy code:
import math

K = 200 #int(input())

total = 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):
            total += math.gcd(ab, c)

print(total)

Fixed code:
import math

K = int(input())

total = 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):
            total += math.gcd(ab, c)

print(total)
Buggy code:
from math import gcd
k=int(input())
cnt=0
for i in range(k):
  for p in range(k):
    for q in range(k):
      cnt+=gcd(i,p,q)
      
print(cnt)
  

Fixed code:
from math import gcd
k=int(input())
cnt=0
for i in range(1,k+1):
  for p in range(1,k+1):
    for q in range(1,k+1):
      gcd1=gcd(i,p)
      
      cnt+=gcd(gcd1,q)

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

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

import math

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

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

print(res)
Buggy code:
import sys
from fractions import gcd
from itertools import combinations
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

K = int(read())
ans = 0

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

Fixed code:
import sys
#from fractions import gcd
from math import gcd
from itertools import combinations
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

K = int(read())
ans = 0

for a in range(1, K + 1):
    for b in range(1, K + 1):
        acc = gcd(a, b)
        for c in range(1, K + 1):
            acc_ = gcd(acc, c)
            ans += acc_
print(ans)
Buggy code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
K = int(input())
count = 0
for i in range(1,K+1):
  for j in range(i+1,K+1):
    for k in range(j+1,K+1):
      count += 6*(gcd(i,j,k))
      
for i in range(1,K+1):
  for j in range(i+1,K+1):
    count += 3*(gcd(i,j))

for i in range(1,K+1):
  count += i
      
print(count)

Fixed code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
  
K = int(input())
count = 0
for i in range(1,K-1):
  for j in range(i+1,K):
    for k in range(j+1,K+1):
      count += 6*(gcd(i,j,k))
      
for i in range(1,K):
  for j in range(i+1,K+1):
    count += 6*(gcd(i,j))

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

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

def gcd2(a,b):
    if b==0:
        return a
    return gcd2(b,a%b)
def gcd3(a,b,c):
    return gcd2(gcd2(a,b),c)

for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(k,K+1):
            if i==j==k:
                ans+=gcd3(i,j,k)
            elif i==j or j==k:
                ans+=gcd3(i,j,k)*3
            else:
                ans+=gcd3(i,j,k)*6

print(ans)


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

def gcd2(a,b):
    if b==0:
        return a
    return gcd2(b,a%b)
def gcd3(a,b,c):
    return gcd2(gcd2(a,b),c)

for i in range(1,K+1):
    for j in range(i,K+1):
        for k in range(j,K+1):
            if i==j==k:
                ans+=gcd3(i,j,k)
            elif i==j or j==k:
                ans+=gcd3(i,j,k)*3
            else:
                ans+=gcd3(i,j,k)*6

print(ans)
Buggy code:
import math

k = int(input())+1

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


print(sum)

Fixed code:
import math
sum = 0
k = int(input())+1
for i in range(1, k):
    for j in range(1, k):
        temp = math.gcd(i, j)
        for x in range(1, k):
            sum += math.gcd(temp, x)
print(sum)
Buggy code:
import math
import fractions

k = input()

sum = 0
for a in range(k):
    for b in range(k):
        x = fractions.gcd(a+1, b+1)
        for c in range(k):
            y = fractions.gcd(x, c+1)
            sum += y
print(sum)


Fixed code:
import math
import fractions

k = input()

sum = 0
for a in range(int(k)):
    for b in range(int(k)):
        x = math.gcd(a+1, b+1)
        for c in range(int(k)):
            y = math.gcd(x, c+1)
            sum += y
print(sum)
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):
        for l in range(1,k+1):
            ans+=gcd(math.gcd(i,j), l)
            #print(gcd(i,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(gcd(i,j,l))
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):
    for k in range(1,k+1):
      ans += math.gcd(math.gcd(i,j), 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):
    for g in range(1,k+1):
      ans += gcd(gcd(i,j), g)

print(ans)
Buggy code:
import math

K = int(input())

sum = 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) :
            sum = sum + math.gcd(a, tmp)

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

print(sum)
Buggy code:
from sys import stdin


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def main():
    k = int(stdin.readline())

    ans = 0

    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * factorial(3) // factorial(3 - len(set([a, b, c])) + 1)

    print(ans)


if __name__ == "__main__":
    main()


Fixed code:
from math import factorial

from sys import stdin


def gcd(x, y):
    if x % y == 0:
        return y
    return gcd(y, x % y)


def main():
    k = int(stdin.readline())

    ans = 0

    for a in range(1, k + 1):
        for b in range(a, k + 1):
            d = gcd(a, b)
            for c in range(b, k + 1):
                e = gcd(d, c)
                ans += e * factorial(3) // factorial(3 - len(set([a, b, c])) + 1)

    print(ans)


if __name__ == "__main__":
    main()
Buggy code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, gcd
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
# from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

K = 200

ans = 0
for a, b, c in combinations_with_replacement(range(1, K+1), 3):
    # print(a, b, c)
    score = gcd(a,gcd(b,c))
    # print(score)
    l = len({a, b, c})
    # print(l)
    if l == 3:
        ans += score*6
    elif l == 2:
        ans += score*3
    else:
        ans += score

print(ans)

Fixed code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, gcd
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
# from fractions import gcd
import sys
def I(): return int(input())  # '123' -> 123
def Is(): return map(int, input().split())  # '123 456' -> 123, 456
def LI(): return list(map(int, input().split()))  # '123 456' -> [123, 456]
def TI(): return tuple(map(int, input().split()))  # '123 456' -> (123, 456)
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()  # 'aa bb' -> 'aa','bb' or ['aa','bb']
def LS(): return list(input())  # 'abc123' -> ['a','b','c','1','2','3']
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(1000000)
MOD = 1000000007
INF = float('inf')

K = I()

ans = 0
for a, b, c in combinations_with_replacement(range(1, K+1), 3):
    # print(a, b, c)
    score = gcd(a,gcd(b,c))
    # print(score)
    l = len({a, b, c})
    # print(l)
    if l == 3:
        ans += score*6
    elif l == 2:
        ans += score*3
    else:
        ans += score

print(ans)
Buggy code:
from math import gcd

k = int(input())

result = 0
for a in range(1, k + 1):
    if a == 1:
        result += 1
        continue
    for b in range(1, k + 1):
        if b == 1:
            result += 1
            continue
        for c in range(1, k + 1):
            result += gcd(gcd(a, b), c)

print(result)


Fixed code:
from math import gcd

k = int(input())

result = 0
for a in range(1, k + 1):
    if a == 1:
        result += k ** 2
        continue
    for b in range(1, k + 1):
        if b == 1:
            result += k
            continue
        for c in range(1, k + 1):
            result += gcd(gcd(a, b), c)

print(result)
Buggy code:
#162C
#Sum of gcd of Tuples (Easy)

import math

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

Fixed code:
#162C
#Sum of gcd of Tuples (Easy)

import math

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