Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)

k = int(input())
val = [[0]*(k+1) for i in range(k+1)]
sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        if(val[i][j] == 0):
            val[i][j] = gcd(i,j)
        for l in range(1,k+1):
            if(val[val[i][j]][l] == 0):
                val[val[i][j]][l] = gcd(val[i][j],l)
            sum = sum + val[val[i][j]][l]

print(sum)

Fixed submission:
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)
 
k = int(input())
val = [[0]*(k+1) for i in range(k+1)]
sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        if(val[i][j] == 0):
            val[i][j] = gcd(i,j)
        for l in range(1,k+1):
            if(val[val[i][j]][l] == 0):
                val[val[i][j]][l] = gcd(val[i][j],l)
            sum = sum + val[val[i][j]][l]
 
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)

sum = 0
k = int(input())
for i in range(1,k+1):
    for j in range(1,k+1):
        val = gcd(i,j)
        for l in range(1,k+1):
            sum = sum + gcd(val,l)

print(sum)

Fixed submission:
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)
 
k = int(input())
val = [[0]*(k+1) for i in range(k+1)]
sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        if(val[i][j] == 0):
            val[i][j] = gcd(i,j)
        for l in range(1,k+1):
            if(val[val[i][j]][l] == 0):
                val[val[i][j]][l] = gcd(val[i][j],l)
            sum = sum + val[val[i][j]][l]
 
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)

sum = 0
k = int(input())
for i in range(1,k+1):
    for j in range(1,k+1):
        val = gcd(i,j)
        for k in range(1,k+1):
            sum = sum + gcd(val,k)

print(sum)

Fixed submission:
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)
 
k = int(input())
val = [[0]*(k+1) for i in range(k+1)]
sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        if(val[i][j] == 0):
            val[i][j] = gcd(i,j)
        for l in range(1,k+1):
            if(val[val[i][j]][l] == 0):
                val[val[i][j]][l] = gcd(val[i][j],l)
            sum = sum + val[val[i][j]][l]
 
print(sum)

Buggy python submission (verdict: Time Limit Exceeded):
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)

sum = 0
k = int(input())
for i in range(1,k+1):
    for j in range(1,k+1):
        for k in range(1,k+1):
            sum = sum + gcd(gcd(i,j),k)

print(sum)

Fixed submission:
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)
 
k = int(input())
val = [[0]*(k+1) for i in range(k+1)]
sum = 0
for i in range(1,k+1):
    for j in range(1,k+1):
        if(val[i][j] == 0):
            val[i][j] = gcd(i,j)
        for l in range(1,k+1):
            if(val[val[i][j]][l] == 0):
                val[val[i][j]][l] = gcd(val[i][j],l)
            sum = sum + val[val[i][j]][l]
 
print(sum)