Buggy python submission (verdict: Runtime Error):
from math import *

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):
            ans += gcd(i, j, k)

print(ans)

Fixed submission:
from math import *

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(tmp, k)

print(ans)

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

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):
            if i == j and j == k and k == i:
                ans += i
            elif i != j and j != k and k != i:
                ans += gcd(gcd(i, j), k) * 6
            else:
                ans += gcd(gcd(i, j), k) * 3

print(ans)

Fixed submission:
from math import *

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(tmp, k)

print(ans)

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

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):
            if i == j and j == k and k == i:
                ans += i
            elif i != j and j != k and k != i:
                ans += gcd(gcd(i, j), k) * 6
            else:
                ans += gcd(gcd(i, j), k) * 3

print(ans)

Fixed submission:
from math import *

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(tmp, k)

print(ans)

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

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):
            if i == j and j == k and k == i:
                ans += i
            elif i != j and j != k and k != i:
                ans += gcd(gcd(i, j), k) * 6
            else:
                ans += gcd(gcd(i, j), k) * 3

print(ans)

Fixed submission:
from math import *

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(tmp, k)

print(ans)

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

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):
            if i == j and j == k and k == i:
                ans += i
            elif i != j and j != k and k != i:
                ans += gcd(gcd(i, j), gcd(j, k)) * 6
            else:
                ans += gcd(gcd(i, j), gcd(j, k)) * 3

print(ans)

Fixed submission:
from math import *

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(tmp, k)

print(ans)

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

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):
            if i == j and j == k and k == i:
                ans += i
            elif i != j and j != k and k != i:
                ans += gcd(gcd(i, j), gcd(j, k)) * 6
            else:
                ans += gcd(gcd(i, j), gcd(j, k)) * 3

print(ans)

Fixed submission:
from math import *

K = int(input())

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        tmp = gcd(i, j)
        for k in range(1, K+1):
            ans += gcd(tmp, k)

print(ans)