Buggy python submission (verdict: Time Limit Exceeded):
import math
K = int(input())
N = 0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            g = math.gcd(a,b)
            g = math.gcd(g,c)
            N += g

print(N)

Fixed submission:
import math
K = int(input())
N = 0

for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            g = math.gcd(a,b)
            g = math.gcd(g,c)
            if(a != 1 or b != 1 or c != 1 ):
                if(a != b or a != c):
                    if(a != K or b != K or c != K ):
                        if(a != b and a != c and b != c):
                            g *= 6
                        else:
                            g *= 3
            N += g

print(N)

Buggy python submission (verdict: Time Limit Exceeded):
from fractions import gcd
K = int(input())
N = 0

for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            g = gcd(a,b)
            g = gcd(g,c)
            if(a != 1 or b != 1 or c != 1 ):
                if(a != b or a != c):
                    if(a != K or b != K or c != K ):
                        if(a != b and a != c and b != c):
                            g *= 6
                        else:
                            g *= 3
            N += g

print(N)

Fixed submission:
import math
K = int(input())
N = 0

for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            g = math.gcd(a,b)
            g = math.gcd(g,c)
            if(a != 1 or b != 1 or c != 1 ):
                if(a != b or a != c):
                    if(a != K or b != K or c != K ):
                        if(a != b and a != c and b != c):
                            g *= 6
                        else:
                            g *= 3
            N += g

print(N)

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

K = int(input())
N = 0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            g = math.gcd(a,b)
            g = math.gcd(g,c)
            N += g

print(N)

Fixed submission:
import math
K = int(input())
N = 0

for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            g = math.gcd(a,b)
            g = math.gcd(g,c)
            if(a != 1 or b != 1 or c != 1 ):
                if(a != b or a != c):
                    if(a != K or b != K or c != K ):
                        if(a != b and a != c and b != c):
                            g *= 6
                        else:
                            g *= 3
            N += g

print(N)

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

K = int(input())
N = 0

for a in range(1,K+1):
    for b in range(1,K+1):
        for c in range(1,K+1):
            g = math.gcd(a,b)
            g = math.gcd(g,c)
            N += g

print(N)

Fixed submission:
import math
K = int(input())
N = 0

for a in range(1,K+1):
    for b in range(a,K+1):
        for c in range(b,K+1):
            g = math.gcd(a,b)
            g = math.gcd(g,c)
            if(a != 1 or b != 1 or c != 1 ):
                if(a != b or a != c):
                    if(a != K or b != K or c != K ):
                        if(a != b and a != c and b != c):
                            g *= 6
                        else:
                            g *= 3
            N += g

print(N)