Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
def pregcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
def gcd(a, b, c):
    d = pregcd(a, pregcd(b, c))
    return d

count = 0
for n in range(1, K+1):
    for m in range(1, K+1):
        for l in range(1, K+1):
            count += gcd(n, m, l)
print(count)

Fixed submission:
K = int(input())
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, n):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += 2 * p
    for k in range(1, K+1):
        q = gcd(l, k)
        count += q
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, K+1):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += p
print(count)

Fixed submission:
K = int(input())
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, n):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += 2 * p
    for k in range(1, K+1):
        q = gcd(l, k)
        count += q
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
def gcd(a, b):
    c = 1
    for i in range(1, min([a+1, b+1]))[::-1]:
        if a%i==0 and b%i==0:
            c = i
            break
        else:
            continue
    return c

count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, K+1):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += p
print(count)

Fixed submission:
K = int(input())
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, n):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += 2 * p
    for k in range(1, K+1):
        q = gcd(l, k)
        count += q
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
def gcd(a, b):
    c = 1
    for i in range(1, min([a+1, b+1])):
        if a%i==0 and b%i==0:
            c = i
    return c

count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, K+1):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += p
print(count)

Fixed submission:
K = int(input())
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, n):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += 2 * p
    for k in range(1, K+1):
        q = gcd(l, k)
        count += q
print(count)

Buggy python submission (verdict: Time Limit Exceeded):
K = int(input())
def gcd(a, b):
    c = 1
    for i in range(1, min([a+1, b+1])):
        if a%i==0 and b%i==0:
            c = i
    return c

count = 0
for n in range(1, K+1):
    for m in range(1, K+1):
        for l in range(1, K+1):
            q = gcd(m, l)
            p = gcd(n, q)
            count += p
print(count)

Fixed submission:
K = int(input())
def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        r = a%b
        a = b
        b = r
    return a
count = 0
temp = list()
for n in range(1, K+1):
    for m in range(1, n):
        temp.append(gcd(n, m))
for l in range(1, K+1):
    for j in range(len(temp)):
        p = gcd(l, temp[j])
        count += 2 * p
    for k in range(1, K+1):
        q = gcd(l, k)
        count += q
print(count)