Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    for i in range(100):
      a, b = b, a%b
      if b == 0:
        return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]
cnt = sum([gcd(gcd(a,b),c) for a in A for b in B for c in C])   
print(cnt)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]

L = [gcd(a,b) for a in A for b in B]

cnt = sum([gcd(l,c) for l in L for c in C])   
print(cnt)

Buggy python submission (verdict: Runtime Error):
def gcd(a, b):
    for i in range(200):
      a, b = b, a%b
      return a if b == 0
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]
cnt = sum([gcd(gcd(a,b),c) for a in A for b in B for c in C])   
print(cnt)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]

L = [gcd(a,b) for a in A for b in B]

cnt = sum([gcd(l,c) for l in L for c in C])   
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import itertools

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(input())
cnt = sum([gcd(gcd(a,b),c) for a,b,c 
           in itertools.product(range(1,K+1), range(1,K+1), range(1,K+1))])   
print(cnt)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]

L = [gcd(a,b) for a in A for b in B]

cnt = sum([gcd(l,c) for l in L for c in C])   
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]
cnt = sum([gcd(gcd(a,b),c) for a in A for b in B for c in C])   
print(cnt)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]

L = [gcd(a,b) for a in A for b in B]

cnt = sum([gcd(l,c) for l in L for c in C])   
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
K = int(input())
A = B = C = [i for i in range(1, K+1)]
cnt = sum([gcd(gcd(a,b),c) for a in A for b in B for c in C])   
print(cnt)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]

L = [gcd(a,b) for a in A for b in B]

cnt = sum([gcd(l,c) for l in L for c in C])   
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
K = int(input())
A = B = C = [i for i in range(1, K+1)]
 
cnt = 0
for a in A:
  for b in B:
    for c in C:
      ans = fractions.gcd(a, b)
      ans = fractions.gcd(ans, c)
      cnt += ans
print(cnt)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]

L = [gcd(a,b) for a in A for b in B]

cnt = sum([gcd(l,c) for l in L for c in C])   
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import fractions
K = int(input())
A = [i for i in range(1, K+1)]
B = [i for i in range(1, K+1)]
C = [i for i in range(1, K+1)]
 
cnt = 0
for a in A:
  for b in B:
    for c in C:
      N = [a,b,c]
      ans = N[0]
      for i in range(1, 3):
        ans = fractions.gcd(ans, N[i])
      cnt += ans
print(cnt)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]

L = [gcd(a,b) for a in A for b in B]

cnt = sum([gcd(l,c) for l in L for c in C])   
print(cnt)

Buggy python submission (verdict: Runtime Error):
import fractions
K = int(input())
A = [i for i in range(1, K)]
B = [i for i in range(1, K)]
C = [i for i in range(1, K)]

cnt = 0
for a in A:
  for b in B:
    for c in C:
      N = [a,b,c]
      ans = N[0]
      for i in range(1, 3):
        ans = fractions.gcd(ans, a[i])
      cnt += ans
print(cnt)

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
  
K = int(input())
A = B = C = [i for i in range(1, K+1)]

L = [gcd(a,b) for a in A for b in B]

cnt = sum([gcd(l,c) for l in L for c in C])   
print(cnt)