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

# def GCD(a,N):
#     gcd = a[0]
#     for i in range(1, N):
#         gcd = math.gcd(gcd, a[i])
#     return gcd


k = int(input())

ans = 0
L = []
G = [0] * k**3

for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            # _l = sorted([i,j,l])
            # if i==1 or j == 1 or l == 1:
            #     ans += 1
            # elif not _l in L:
            #     L.append(_l)
            #     g = GCD(_l, 3)
            #     G[L.index(_l)] = g
            #     ans += g
            # else:
            #     ans += G[L.index(_l)]
            ans += gcd(i,gcd(j,l))

print(ans)

Fixed submission:
from math import gcd

# def GCD(a,N):
#     gcd = a[0]
#     for i in range(1, N):
#         gcd = math.gcd(gcd, a[i])
#     return gcd


k = int(input())

ans = 0
L = []
G = [0] * k**3

for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            # _l = sorted([i,j,l])
            # if i==1 or j == 1 or l == 1:
            #     ans += 1
            # elif not _l in L:
            #     L.append(_l)
            #     g = GCD(_l, 3)
            #     G[L.index(_l)] = g
            #     ans += g
            # else:
            #     ans += G[L.index(_l)]
            ans += gcd(i,gcd(j,l))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def GCD(a,N):
    gcd = a[0]
    for i in range(1, N):
        gcd = math.gcd(gcd, a[i])
    return gcd


k = int(input())
# h, w = map(int, input().split())
# a = list(map(int, input().split()))
ans = 0
L = []
G = [0] * k**3
for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            _l = sorted([i,j,l])
            if not _l in L:
                L.append(_l.sort())
                g = GCD(_l, 3)
                G[L.index(_l.sort())] = g
                ans += g
            else:
                ans += G[L.index(_l.sort())]
            # ans += 1

print(ans)

Fixed submission:
from math import gcd

# def GCD(a,N):
#     gcd = a[0]
#     for i in range(1, N):
#         gcd = math.gcd(gcd, a[i])
#     return gcd


k = int(input())

ans = 0
L = []
G = [0] * k**3

for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            # _l = sorted([i,j,l])
            # if i==1 or j == 1 or l == 1:
            #     ans += 1
            # elif not _l in L:
            #     L.append(_l)
            #     g = GCD(_l, 3)
            #     G[L.index(_l)] = g
            #     ans += g
            # else:
            #     ans += G[L.index(_l)]
            ans += gcd(i,gcd(j,l))

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
def GCD(a,N):
    gcd = a[0]
    for i in range(1, N):
        gcd = math.gcd(gcd, a[i])
    return gcd


k = int(input())
# h, w = map(int, input().split())
# a = list(map(int, input().split()))
ans = 0
L = []
for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            if i==1 or j==1 or l==1:
                ans += 1
            else:
                ans += GCD([i,j,l], 3)

print(ans)

Fixed submission:
from math import gcd

# def GCD(a,N):
#     gcd = a[0]
#     for i in range(1, N):
#         gcd = math.gcd(gcd, a[i])
#     return gcd


k = int(input())

ans = 0
L = []
G = [0] * k**3

for i in range(1, k+1):
    for j in range(1, k+1):
        for l in range(1, k+1):
            # _l = sorted([i,j,l])
            # if i==1 or j == 1 or l == 1:
            #     ans += 1
            # elif not _l in L:
            #     L.append(_l)
            #     g = GCD(_l, 3)
            #     G[L.index(_l)] = g
            #     ans += g
            # else:
            #     ans += G[L.index(_l)]
            ans += gcd(i,gcd(j,l))

print(ans)