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

K = int(input())
g = 0
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = fractions.gcd(i, j)
            b = fractions.gcd(a, k)
            if i != j != k:
                g += b*6
            elif i == j == k:
                g += b
            else:
                g += b*3


print(g)


Fixed submission:
import math

K = int(input())
g = 0
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = math.gcd(i, j)
            b = math.gcd(a, k)
            if i != j != k:
                g += b*6
            elif i == j == k:
                g += b
            else:
                g += b*3

print(g)

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

K = int(input())
g = []
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = fractions.gcd(i, j)
            b = fractions.gcd(a, k)
            if i != j != k:
                g.append(b)
                g.append(b)
                g.append(b)
                g.append(b)
                g.append(b)
                g.append(b)
            elif i == j == k:
                g.append(b)
            else:
                g.append(b)
                g.append(b)
                g.append(b)

print(sum(g))

Fixed submission:
import math

K = int(input())
g = 0
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = math.gcd(i, j)
            b = math.gcd(a, k)
            if i != j != k:
                g += b*6
            elif i == j == k:
                g += b
            else:
                g += b*3

print(g)

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

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.combinations_with_replacement(K, 3)
p = list(p)
g = []

for i in p:
    a = fractions.gcd(i[0], i[1])
    b = fractions.gcd(a, i[2])
    if i[0] != i[1] != i[2]:
        g.append(b)
        g.append(b)
        g.append(b)
        g.append(b)
        g.append(b)
        g.append(b)
    elif i[0] == i[1] == i[2]:
        g.append(b)
    else:
        g.append(b)
        g.append(b)
        g.append(b)


print(sum(g))


Fixed submission:
import math

K = int(input())
g = 0
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = math.gcd(i, j)
            b = math.gcd(a, k)
            if i != j != k:
                g += b*6
            elif i == j == k:
                g += b
            else:
                g += b*3

print(g)

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

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.product(K, repeat=3)
p = list(p)

g = []

for i in p:
    a = fractions.gcd(i[0], i[1])
    b = fractions.gcd(a, i[2])
    g.append(b)

print(sum(g))


Fixed submission:
import math

K = int(input())
g = 0
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = math.gcd(i, j)
            b = math.gcd(a, k)
            if i != j != k:
                g += b*6
            elif i == j == k:
                g += b
            else:
                g += b*3

print(g)

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

K = int(input())
K = [i for i in range(1, K+1)]
p = itertools.product(K, repeat=3)
p = list(p)

g = []

for i in p:
    g.append(fractions.gcd(i[0], i[1]))

for i in range(len(g)):
    g[i] = fractions.gcd(g[i], p[i][2])

print(sum(g))

Fixed submission:
import math

K = int(input())
g = 0
for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            a = math.gcd(i, j)
            b = math.gcd(a, k)
            if i != j != k:
                g += b*6
            elif i == j == k:
                g += b
            else:
                g += b*3

print(g)