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

K = int(input())
total = 0


def gcd_list(*numbers):
    return reduce(math.gcd, numbers)


for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            s = [i, j, k]
            total += gcd_list(*s)

print(total)


Fixed submission:
import math
from functools import reduce

K = int(input())
total = 0


def gcd_list(*numbers):
    return reduce(math.gcd, numbers)


for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            s = [i, j, k]
            if i == j == k:
                total += gcd_list(*s)
            elif i == j and j != k:
                total += gcd_list(*s) * 3
            elif i != j and j == k:
                total += gcd_list(*s) * 3
            else:
                total += gcd_list(*s) * 6

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
total = 0


def ab_gcd(a: int, b: int):
    small = min(a, b)
    large = max(a, b)
    r = large % small
    if r != 0:
        return ab_gcd(r, small)
    else:
        return small


for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            gcd1 = ab_gcd(i, j)
            gcd2 = ab_gcd(k, gcd1)
            if i == j == k:
                total += gcd2
            elif i == j and j != k:
                total += gcd2 * 3
            elif i != j and j == k:
                total += gcd2 * 3
            else:
                total += gcd2 * 6

print(total)


Fixed submission:
import math
from functools import reduce

K = int(input())
total = 0


def gcd_list(*numbers):
    return reduce(math.gcd, numbers)


for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            s = [i, j, k]
            if i == j == k:
                total += gcd_list(*s)
            elif i == j and j != k:
                total += gcd_list(*s) * 3
            elif i != j and j == k:
                total += gcd_list(*s) * 3
            else:
                total += gcd_list(*s) * 6

print(total)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
total = 0


def ab_gcd(a: int, b: int):
    small = min(a, b)
    large = max(a, b)
    r = large % small
    if r != 0:
        return ab_gcd(r, small)
    else:
        return small


for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            gcd1 = ab_gcd(i, j)
            gcd2 = ab_gcd(j, k)
            gcd3 = ab_gcd(gcd1, gcd2)
            if i == j == k:
                total += gcd3
            elif i == j and j != k:
                total += gcd3 * 3
            elif i != j and j == k:
                total += gcd3 * 3
            else:
                total += gcd3 * 6

print(total)


Fixed submission:
import math
from functools import reduce

K = int(input())
total = 0


def gcd_list(*numbers):
    return reduce(math.gcd, numbers)


for i in range(1, K+1):
    for j in range(1, i+1):
        for k in range(1, j+1):
            s = [i, j, k]
            if i == j == k:
                total += gcd_list(*s)
            elif i == j and j != k:
                total += gcd_list(*s) * 3
            elif i != j and j == k:
                total += gcd_list(*s) * 3
            else:
                total += gcd_list(*s) * 6

print(total)