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

def gcd(a,b):
    if a ==b:
        return a
    elif a !=b:
        return math.gcd(a,b)
    
    
        
cnt=0
K = int(input())
for i in range(1,K+1):
    for m in range(1,K+1):
        c = gcd(i,m)
        for u in range(1,K+1):
            cnt+= gcd(c,u)
print(cnt)

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

def gcd(a,b):
    return math.gcd(a,b)
cnt=0
for i in range(1,K+1):
    for m in range(1,K+1):
        d = math.gcd(i,m)
        for u in range(1,K+1):
            cnt+=math.gcd(d,u)
            
print(cnt)

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

def gcd(a,b,c):
    if a == b==c:
        return a
    elif a ==b and b!=c :
        return math.gcd(a,c)
    elif a ==c and b!=c:
        return math.gcd(a,b)
    elif b ==c and a!=c:
        return math.gcd(a,b)
    else:
        return math.gcd(math.gcd(a,b),c)
        
cnt=0
K = int(input())
for i in range(1,K+1):
    for m in range(1,K+1):
        for u in range(1,K+1):
            cnt += gcd(i,m,u)
print(cnt)

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

def gcd(a,b):
    return math.gcd(a,b)
cnt=0
for i in range(1,K+1):
    for m in range(1,K+1):
        d = math.gcd(i,m)
        for u in range(1,K+1):
            cnt+=math.gcd(d,u)
            
print(cnt)

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

def gcd(a,b,c):
    if a == b==c:
        return a
    elif a ==b and b!=c :
        return math.gcd(a,c)
    elif a ==c and b!=c:
        return math.gcd(a,b)
    elif b ==c and a!=c:
        return math.gcd(a,b)
    else:
        d = math.gcd(a,b)
        return math.gcd(d,c)
        
cnt=0
K = int(input())
for i in range(1,K+1):
    for m in range(1,K+1):
        for u in range(1,K+1):
            cnt +=gcd(i,m,u)
print(cnt)

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

def gcd(a,b):
    return math.gcd(a,b)
cnt=0
for i in range(1,K+1):
    for m in range(1,K+1):
        d = math.gcd(i,m)
        for u in range(1,K+1):
            cnt+=math.gcd(d,u)
            
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(a,b,c):
    d = math.gcd(a,b)
    return math.gcd(d,c)
cnt =0
L =[]
K = int(input())
for i in range(1,K+1):
    for m in range(1,K+1):
        for u in range(1,K+1):
            L.append(gcd(i,m,u))
print(sum(L))

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

def gcd(a,b):
    return math.gcd(a,b)
cnt=0
for i in range(1,K+1):
    for m in range(1,K+1):
        d = math.gcd(i,m)
        for u in range(1,K+1):
            cnt+=math.gcd(d,u)
            
print(cnt)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

def gcd(a,b,c):
    d = math.gcd(a,b)
    return math.gcd(d,c)
cnt =0
K = int(input())
for i in range(1,K+1):
    for m in range(1,K+1):
        for u in range(1,K+1):
            cnt+= gcd(i,m,u)
print(cnt)

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

def gcd(a,b):
    return math.gcd(a,b)
cnt=0
for i in range(1,K+1):
    for m in range(1,K+1):
        d = math.gcd(i,m)
        for u in range(1,K+1):
            cnt+=math.gcd(d,u)
            
print(cnt)