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

k = int(input())

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

    
print(total)


Fixed submission:
from math import gcd
from collections import defaultdict

k = int(input())

memo = defaultdict(defaultdict)

rg = range(1, k + 1)
for i in rg:
    for j in rg:
        memo[i][j] = memo[j][i] = gcd(i, j)

ret = 0
for i in rg:
    for j in rg:
        tmp = memo[i][j]
        for k in rg:
            res = memo[k][tmp]
            ret += res

print(ret)

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

k = int(input())

total = 0
ran = range(1, k + 1)
for i, j, k in itertools.product(ran, ran, ran):
    total += math.gcd(math.gcd(i, j), k)
    
print(total)

Fixed submission:
from math import gcd
from collections import defaultdict

k = int(input())

memo = defaultdict(defaultdict)

rg = range(1, k + 1)
for i in rg:
    for j in rg:
        memo[i][j] = memo[j][i] = gcd(i, j)

ret = 0
for i in rg:
    for j in rg:
        tmp = memo[i][j]
        for k in rg:
            res = memo[k][tmp]
            ret += res

print(ret)

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

k = int(input())

def extract_gcd(limit):
    ran = range(1, limit + 1)
    for i in ran:
        for j in ran:
            for k in ran:
                yield math.gcd(math.gcd(i, j), k)
total = 0
for n in extract_gcd(k):
    total += n
    
print(total)
    


Fixed submission:
from math import gcd
from collections import defaultdict

k = int(input())

memo = defaultdict(defaultdict)

rg = range(1, k + 1)
for i in rg:
    for j in rg:
        memo[i][j] = memo[j][i] = gcd(i, j)

ret = 0
for i in rg:
    for j in rg:
        tmp = memo[i][j]
        for k in rg:
            res = memo[k][tmp]
            ret += res

print(ret)

Buggy python submission (verdict: Runtime Error):
k = int(input())

def extract_gcd(limit):
    ran = range(1, limit + 1)
    for i in ran:
        for j in ran:
            for k in ran:
                yield math.gcd(math.gcd(i, j), k)
total = 0
for n in extract_gcd(k):
    total += n
    
print(total)

Fixed submission:
from math import gcd
from collections import defaultdict

k = int(input())

memo = defaultdict(defaultdict)

rg = range(1, k + 1)
for i in rg:
    for j in rg:
        memo[i][j] = memo[j][i] = gcd(i, j)

ret = 0
for i in rg:
    for j in rg:
        tmp = memo[i][j]
        for k in rg:
            res = memo[k][tmp]
            ret += res

print(ret)

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

k = int(input())

seq = []
ran = range(1, k + 1)
for i in ran:
    for j in ran:
        for k in ran:
            n = reduce(lambda x, y: math.gcd(x, y), (i, j, k))
            seq.append(n)

print(sum(seq))

Fixed submission:
from math import gcd
from collections import defaultdict

k = int(input())

memo = defaultdict(defaultdict)

rg = range(1, k + 1)
for i in rg:
    for j in rg:
        memo[i][j] = memo[j][i] = gcd(i, j)

ret = 0
for i in rg:
    for j in rg:
        tmp = memo[i][j]
        for k in rg:
            res = memo[k][tmp]
            ret += res

print(ret)