Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
H, W = map(int, input().split())
area = []
for i in range(H):
  area.append(input())

for i in range(H):
  for j in range(W):
    if area[i][j] == '#':
      print('#', end='')
    else:
      count = 0
      for k in range(max(0, i-1), min(i+1, H-1)+1):
        for l in range(max(0, j-1), min(j+1, W-1)+1):
          if area[k][l] == '#':
            count += 1
      print(count, end='')
  print()


Fixed submission:
a, b, c = map(int, input().split())

if a == b:
    print(c)
elif b == c:
    print(a)
else:
    print(b)
Buggy python submission (verdict: Runtime Error):
import math

A, B, C = map(int, input().split())

gcd = math.gcd(A, B)
if C % gcd == 0:
    print("YES")
else:
    print("NO")


Fixed submission:
import fractions

A, B, C = map(int, input().split())

gcd = fractions.gcd(A, B)
if C % gcd == 0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

A = [input() for n in range(N)]
B = [input() for m in range(M)]

ans = "Yes"
for a in A:
    for b in B:
        print(a, b)
        if b not in a:
            ans = "No"
print(ans)


Fixed submission:
a, b = map(int, input().split())


if a == b:
    print("Draw")
elif a == 1:
    print("Alice")
elif b == 1:
    print("Bob")
elif a > b:
    print("Alice")
elif a < b:
    print("Bob")

Buggy python submission (verdict: Runtime Error):
N, M = map(int, input().split())

A = [input() for n in range(N)]
B = [input() for m in range(M)]
for a in A:
    cnt = 0
    for b in B:
        if b in a:
            cnt += 1
        else:
            cnt = 0
        if cnt == M:
            print("Yes")
            exit()

print("No")


Fixed submission:
a, b = map(int, input().split())


if a == b:
    print("Draw")
elif a == 1:
    print("Alice")
elif b == 1:
    print("Bob")
elif a > b:
    print("Alice")
elif a < b:
    print("Bob")

Buggy python submission (verdict: Runtime Error):
a, b = input().split()

cards = {"2": 1, "3": 2, "4": 3, "5": 4, "6": 5, "7": 6, "8": 7, "9 ": 8, "10": 9, "11": 10, "12": 11, "13": 12, "1": 13 }

if cards[a] > cards[b]:
    print("Alice")
elif cards[a] < cards[b]:
    print("Bob")
else:
    print("Draw")


Fixed submission:
a, b = map(int, input().split())


if a == b:
    print("Draw")
elif a == 1:
    print("Alice")
elif b == 1:
    print("Bob")
elif a > b:
    print("Alice")
elif a < b:
    print("Bob")

Buggy python submission (verdict: Runtime Error):
a, b = input().split()

cards = {"2": 1, "3": 2, "4": 3, "5": 4, "6": 5, "7": 6, "8": 7, "9 ": 8, "10": 9, "11": 10, "12": 11, "13": 12, "1": 13 }

if cards[a] > cards[b]:
    print("Alice")
elif cards[a] < cards[b]:
    print("Bob")
else:
    print("Draw")


Fixed submission:
a, b = map(int, input().split())


if a == b:
    print("Draw")
elif a == 1:
    print("Alice")
elif b == 1:
    print("Bob")
elif a > b:
    print("Alice")
elif a < b:
    print("Bob")
Buggy python submission (verdict: Runtime Error):
import copy

n = int(input())
t = list(map(int, input().split()))
sum_t = sum(t)


m = int(input())
for _ in range(m):
    idx, value = map(int, input().split())
    print(sum_t - t[idx - 1] + value)



Fixed submission:
a, op, b = input().split()

print(eval(a + op + b))
Buggy python submission (verdict: Runtime Error):
import re

S = input()

s = re.sub(r"(dreamer)|(eraser)", "", s)
s = re.sub(r"(dream)|(erase)", "", S)

if len(s) == 0:
    print("YES")
else:
    print("NO")

Fixed submission:
S = input()

s = S.replace("eraser", "").replace("erase", "").replace("dreamer", "").replace("dream", "")
if len(s) == 0:
    print("YES")
else:
    print("NO")
Buggy python submission (verdict: Time Limit Exceeded):
a, b, x= map(int, input().split())

l = [i for i in range(a, b + 1) if i % x == 0]
print(len(l))


Fixed submission:
a, b, x= map(int, input().split())

print((b // x) - ((a - 1) // x))
Buggy python submission (verdict: Runtime Error):
s = input()
ans = []

for i, j in enumerate(s):
    if j in ["0", "1"]:
        ans.append(j)
    else:
        if len(ans):
            del ans[i - 1]

print("".join(ans))

Fixed submission:
s = input()
ans = []

for i in s:
    if i in ["0", "1"]:
        ans.append(i)
    else:
        if len(ans):
            ans.pop()

print("".join(ans))
Buggy python submission (verdict: Runtime Error):
N = int(input())
Ai = list(map(int, input().split()))
     
result = 1
     
if 0 in Ai:
	result= '0'  
else:
  for i in range(N):
      result *= Ai[i]
      if result > 10**18:
        result = '-1'
     
print(result)

Fixed submission:
a,b = map(int, input().split())

print(a * b)

Buggy python submission (verdict: Runtime Error):
N = int(input())
Ai = list(map(int, input().split()))

result = 1

if 0 in Ai:
	result= '0'  
else:
  for i in range(N):
      result *= Ai[i]

  	if result > 10**18:
    	result = '-1'

print(result)

Fixed submission:
a,b = map(int, input().split())

print(a * b)

Buggy python submission (verdict: Runtime Error):
N = int(input())
Ai = list(map(int, input().split()))

result = 1
for i in Ai:
	result *= i

if result > 10**18:
  result = '-1'

print(result)

Fixed submission:
a,b = map(int, input().split())

print(a * b)

Buggy python submission (verdict: Runtime Error):
S1, S2 = input().strip().split()
print(S1*S2)

Fixed submission:
a,b = map(int, input().split())

print(a * b)
Buggy python submission (verdict: Runtime Error):
N = int(input())
Ai = list(map(int, input().split()))
     
result = 1
     
if 0 in Ai:
  result= '0'  
else:
  for i in range(N):
    result *= Ai[i]
      if result > 10**18:
        result = '-1'
     
print(result)

Fixed submission:
import sys
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print(0)
    sys.exit()
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        sys.exit()
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
Ai = list(map(int, input().split()))
     
result = 1
     
if 0 in Ai:
	result= '0'  
else:
  for i in range(N):
      result *= Ai[i]
      if result > 10**18:
        result = '-1'
     
print(result)

Fixed submission:
import sys
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print(0)
    sys.exit()
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        sys.exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Ai = list(map(int, input().split()))

result = 1

if 0 in Ai:
	result= '0'  
else:
  for i in range(N):
      result *= Ai[i]

  if result > 10**18:
    result = '-1'

print(result)

Fixed submission:
import sys
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print(0)
    sys.exit()
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        sys.exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
Ai = list(map(int, input().split()))

result = 1
for i in Ai:
	result *= i

if result > 10**18:
  result = '-1'

print(result)

Fixed submission:
import sys
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print(0)
    sys.exit()
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        sys.exit()
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import sys
N = int(input())
A_list = list(map(int ,input().split()))

s = 1


for i in range(len(A_list)):
        s = s*A_list[i]
        if A_list[i] == 0:
            print("0")
            sys.exit()
if s>pow(10,18):
        print("-1")
else:
        print(s)

Fixed submission:
import sys
N = int(input())
A_list = list(map(int ,input().split()))

s = 1

A_list.sort()
if A_list[0]==0:
    print("0")
    sys.exit()
for i in range(len(A_list)):
        s = s*A_list[i]
        if s>pow(10,18):
            print("-1")
            sys.exit()

print(s)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int ,input().split()))
sorted(A_list)

s = 1
if A_list[0] == 0:
    print("0")
else :
    for i in range(len(A_list)):
        s = s*A_list[i]
    if s>pow(10,18):
        print("-1")
    else:
        print(s)

Fixed submission:
import sys
N = int(input())
A_list = list(map(int ,input().split()))

s = 1

A_list.sort()
if A_list[0]==0:
    print("0")
    sys.exit()
for i in range(len(A_list)):
        s = s*A_list[i]
        if s>pow(10,18):
            print("-1")
            sys.exit()

print(s)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
city_list = list(map(int, input().split()))
th_list = []
n = 0
count = 0
for i in range(N):
    count += 1
    th_list.append(n)
#   print(n)
    n = city_list[n] - 1
''' if n in th_list:
        #繰り返されている個数を出す
        num = len(th_list)-th_list.index(n)
        break'''
 
#print(city_list, th_list)
count = -1
for i in range(N):
    if th_list.count(th_list[i]) > 1:
        break
list = [x for x, l in enumerate(th_list) if l == th_list[i]]
#print(list)
#print(list[0])
#print(th_list)
if K > N:
    print(th_list[(K-list[0])%(list[1]-list[0])+list[0]]+1)
else:
    print(th_list[K]+1)

Fixed submission:
S = input()
T = input()
x = [chr(i) for i in range(97, 97+26)]
list = []
for i in range(26):
    list.append(S+x[i])
if T in list:
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
A, B, C, K = map(int, input().split())
sum = 0
while K !=0:
    K = K - 1
    if A == 0 and B == 0:
        sum = sum - 1
    else :
        if A == 0:
            B = B -1
            sum = sum
        else:
            A = A -1
            sum = sum + 1
print(sum)

Fixed submission:
A,B,C,K = map(int,input().split())
if A >= K:
    print(K)
else :
    if (K-A) <= B:
        print(A)
    else:
        print(A-(K-A-B))
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
city_list = list(map(int, input().split()))
th_list = []
n = 0
count = 0
for i in range(N):
    count += 1
    th_list.append(n)
#   print(n)
    n = city_list[n] - 1
''' if n in th_list:
        #繰り返されている個数を出す
        num = len(th_list)-th_list.index(n)
        break'''
 
#print(city_list, th_list)
count = -1
for i in range(N):
    if th_list.count(th_list[i]) > 1:
        break
list = [x for x, l in enumerate(th_list) if l == th_list[i]]
#print(list)
#print(list[0])
#print(th_list)
if K > N:
    print(th_list[(K-list[0])%(list[1]-list[0])+list[0]]+1)
else:
    print(th_list[K]+1)

Fixed submission:
import collections

N, K = map(int, input().split())
city_list = list(map(int, input().split()))
th_list = []
n = 0
for i in range(N):
    th_list.append(n)
    n = city_list[n] - 1

c = collections.Counter(th_list)
for i in range(N):
    if c[th_list[i]] > 1:
        break
list = [x for x, l in enumerate(th_list) if l == th_list[i]]

if K > N:
    print(th_list[(K - list[0]) % (list[1] - list[0]) + list[0]] + 1)
else:
    print(th_list[K] + 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
city_list = list(map(int, input().split()))
th_list = []
n = 0
count = 0
for i in range(N):
    count += 1
    th_list.append(n)
#   print(n)
    n = city_list[n] - 1
''' if n in th_list:
        #繰り返されている個数を出す
        num = len(th_list)-th_list.index(n)
        break'''

#print(city_list, th_list)
count = -1
for i in range(N):
    if th_list.count(th_list[i]) > 1:
        break
list = [x for x, l in enumerate(th_list) if l == th_list[i]]
#print(list)
#print(list[0])
#print(th_list)
if K > N:
    print(th_list[(K-list[0])%(list[1]-list[0])+list[0]]+1)
else:
    print(th_list[K]+1)

Fixed submission:
import collections

N, K = map(int, input().split())
city_list = list(map(int, input().split()))
th_list = []
n = 0
for i in range(N):
    th_list.append(n)
    n = city_list[n] - 1

c = collections.Counter(th_list)
for i in range(N):
    if c[th_list[i]] > 1:
        break
list = [x for x, l in enumerate(th_list) if l == th_list[i]]

if K > N:
    print(th_list[(K - list[0]) % (list[1] - list[0]) + list[0]] + 1)
else:
    print(th_list[K] + 1)
Buggy python submission (verdict: Runtime Error):
a = list(map(int,input().split()))
 
A = a[0]
B = a[1]
C = a[2]
D = a[3]
 
while B>0 and D>0:
  D = D - A
  if D <= 0:
    print("No")
    break
  B = B - D
  if B <= 0:
    print("Yes")
    break


Fixed submission:
a = list(map(int,input().split()))

if a[1] >= a[0] :
  print("unsafe")
else: 
  print("safe")
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
n = int(N)
a = [input() for i in range(n)]
b = []
for i in range(n):
  if (a[i]in b) == False:
    b.append(a[i])
  
print(len(b))

Fixed submission:
N = input()
n = int(N)
a = {input() for i in range(n)}  
print(len(a))

Buggy python submission (verdict: Time Limit Exceeded):
N = input()
a = []
for i in range(int(N)):
  x = input()
  TF = x in a
  if TF != True:
    a.append(x)
print(len(a))

Fixed submission:
N = input()
n = int(N)
a = {input() for i in range(n)}  
print(len(a))

Buggy python submission (verdict: Time Limit Exceeded):
N = input()
a = []
for i in range(int(N)):
  x = input()
  
  if str(x in a) != "True":
    a.append(x)
print(len(a))

Fixed submission:
N = input()
n = int(N)
a = {input() for i in range(n)}  
print(len(a))
Buggy python submission (verdict: Time Limit Exceeded):
N = input()
a = list(map(int,input().split()))

for i in range(int(N)):
	print(a.count(i+1))

Fixed submission:
N = input()
N = int(N)
a = list(map(int,input().split()))
s =[0]*N
for i in range(N-1):
	s[a[i]-1]+=1
    
for i in range(N):
	print(s[i])
Buggy python submission (verdict: Runtime Error):
a,b=(int(x) for x in input().split())

if a==1 or b == 1:
  print("0")
else if a*b%2==0:
    print(int(a*b/2))
else:
    print(int((a*b-1)/2+1))

Fixed submission:
x = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
N = int(input())
print(x[N-1])
Buggy python submission (verdict: Runtime Error):
import numpy
N,K = map(int,input().split())
H = list(map(int,input().split()))

H = numpy.sort(H)
#print(H)

for i in range(K):
  H.remove(H[N-1-i])

print(sum(H))

Fixed submission:
import numpy
N,K = map(int,input().split())
H = list(map(int,input().split()))

H = numpy.sort(H)
sum = 0
#print(H)
if N-K > 0:
  for i in range(N-K):
    sum = sum + H[i]
else:
    sum = 0
    
print(sum)

Buggy python submission (verdict: Runtime Error):
N,K = map(int,input().split())
H = list(map(int,input().split()))

H = sorted(H)
#print(H)

for i in range(K):
  H.remove(H[N-1-i])

print(sum(H))

Fixed submission:
import numpy
N,K = map(int,input().split())
H = list(map(int,input().split()))

H = numpy.sort(H)
sum = 0
#print(H)
if N-K > 0:
  for i in range(N-K):
    sum = sum + H[i]
else:
    sum = 0
    
print(sum)
Buggy python submission (verdict: Runtime Error):
x=input()
list=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z]

for i in range(26):
  if list[i] = x:
    print(list[i+i])

Fixed submission:
x = input()
list = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']

for i in range(26):
    if list[i] == x:
        print(list[i + 1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
word = list(input())
count = 0
for i in range(N-2):
  if word[i]=A and word[i+1]=B and word[i+2]=C:
    count += 1
    
print(count)

Fixed submission:
N = int(input())
word = list(input())
count = 0
for i in range(N - 2):
    if word[i]=="A" and word[i+1]=="B" and word[i+2]=="C":
        count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
S = input()
num = 0
for i in range(len(S))
	if S[i] == '+':
    	num = num + 1
    else:
    	num = num - 1
print(num)

Fixed submission:
S = input()
num = 0
for i in range(len(S)):
    if S[i] == '+': num = num + 1
    else : num = num -1
print(num)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int, input().split()))
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    A_list = [C if j == B else j for j in A_list]
    print(sum(A_list))

Fixed submission:
import collections

N = int(input())
A_list = list(map(int, input().split()))
A_count_list = collections.Counter(A_list)
A_sum = sum(A_list)
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    A_sum += (C - B)*A_count_list[B]
    A_count_list[C] += A_count_list[B]
    A_count_list[B] = 0
    print(A_sum)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A_list = list(map(int, input().split()))
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    temp = [C if j == B else j for j in A_list]
    print(sum(temp))
    A_list = temp.copy()

Fixed submission:
import collections

N = int(input())
A_list = list(map(int, input().split()))
A_count_list = collections.Counter(A_list)
A_sum = sum(A_list)
Q = int(input())
for _ in range(Q):
    B, C = map(int, input().split())
    A_sum += (C - B)*A_count_list[B]
    A_count_list[C] += A_count_list[B]
    A_count_list[B] = 0
    print(A_sum)
Buggy python submission (verdict: Time Limit Exceeded):
from operator import mul
from functools import reduce

N = int(input())
input_list = [int(i) for i in input().split()]

sum_num = reduce(mul, input_list)

if sum_num > 10 ** 18:
    print('-1')
else:
    print(sum_num)

Fixed submission:
N = int(input())
input_list = [int(i) for i in input().split()]
max_num = 10 ** 18

sum_num = 1
if 0 in input_list:
    print('0')
else:
    for i in input_list:
        sum_num *= i
        if sum_num > max_num:
            sum_num = -1
            break
    print(sum_num)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
input_list = input().split()

sum_num = 1
for t in input_list:
    sum_num *= int(t)

if sum_num > 10 ** 18:
    print('-1')
else:
    print(sum_num)

Fixed submission:
N = int(input())
input_list = [int(i) for i in input().split()]
max_num = 10 ** 18

sum_num = 1
if 0 in input_list:
    print('0')
else:
    for i in input_list:
        sum_num *= i
        if sum_num > max_num:
            sum_num = -1
            break
    print(sum_num)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
input_list = [int(i) for i in input().split()]

sum_num = 1
for t in input_list:
    sum_num *= t


if sum_num > 10 ** 18:
    print('-1')
else:
    print(sum_num)

Fixed submission:
N = int(input())
input_list = [int(i) for i in input().split()]
max_num = 10 ** 18

sum_num = 1
if 0 in input_list:
    print('0')
else:
    for i in input_list:
        sum_num *= i
        if sum_num > max_num:
            sum_num = -1
            break
    print(sum_num)
Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
loads = []
count = 0
for k in range(m):
    load = list(map(int, input().split()))
    loads.append(load)

for h in range(n):
    for load in loads:
        if h+1 in load:
            op = sum(load)-(h+1)-1
            if h_list[h] <= h_list[op]:
                break
    else:
        count += 1

print(count)

Fixed submission:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
loads = [[0] for i in range(n)]
count = 0
for k in range(m):
    start, end = map(int, input().split())
    loads[start-1].append(h_list[end-1])
    loads[end-1].append(h_list[start-1])

for k in range(n):
    if h_list[k] > max(loads[k]):
        count += 1

print(count)

Buggy python submission (verdict: Time Limit Exceeded):
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
loads = []
count = 0
for k in range(m):
    load = list(map(int, input().split()))
    loads.append(load)

for h in range(n):
    for load in loads:
        if h+1 in load:
            op = sum(load)-(h+1)-1
            if h_list[h] <= h_list[op]:
                h_count = 0
                break
    else:
        h_count = 1
        count += h_count

print(count)

Fixed submission:
n, m = map(int, input().split())
h_list = list(map(int, input().split()))
loads = [[0] for i in range(n)]
count = 0
for k in range(m):
    start, end = map(int, input().split())
    loads[start-1].append(h_list[end-1])
    loads[end-1].append(h_list[start-1])

for k in range(n):
    if h_list[k] > max(loads[k]):
        count += 1

print(count)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
S = []
for _ in range(N):
    i = input()
    if i not in S:
        S.append(i)

print(len(S))


Fixed submission:
N = int(input())
S = []
for _ in range(N):
    S.append(input())

print(len(set(S)))
Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
mod_list = []

for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        num = int(''.join(S[i:j]))
        mod_list.append(num % 2019)

print(len([i for i in mod_list if i == 0]))

Fixed submission:
S = list(input())[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1  # If 2019 is exist, count number
current = 0
x = 1
for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current]
    mods[current] += 1
    x = x * 10 % 2019

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
count = 0

for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        num = int(''.join(S[i:j]))
        if num % 2019 == 0:
            count += 1

print(count)



Fixed submission:
S = list(input())[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1  # If 2019 is exist, count number
current = 0
x = 1
for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current]
    mods[current] += 1
    x = x * 10 % 2019

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
S = list(input())
count = 0

for i in range(len(S)-3):
    for j in range(i+4, len(S)+1):
        num = int(''.join(S[i:j]))
        if num % 2019 == 0:
            count += 1

print(count)


Fixed submission:
S = list(input())[::-1]
ans = 0
mods = [0] * 2019
mods[0] = 1  # If 2019 is exist, count number
current = 0
x = 1
for s in S:
    current = (current + x * int(s)) % 2019
    ans += mods[current]
    mods[current] += 1
    x = x * 10 % 2019

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

K = int(input())
count = 0
for abc in list(itertools.product(list(range(1, K+1)), repeat=3)):
    count += reduce(math.gcd, abc)

print(count)

Fixed submission:
import math

count = 0

K = int(input())
for a in range(1, K+1):
    for b in range(1, K+1):
        temp = math.gcd(a, b)
        for c in range(1, K+1):
            count += math.gcd(temp, c)

print(count)

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

K = int(input())
count = 0
for a in range(1, K+1):
    for b in range(1, K+1):
        for c in range(1, K+1):
            count += reduce(math.gcd, (a, b, c))

print(count)


Fixed submission:
import math

count = 0

K = int(input())
for a in range(1, K+1):
    for b in range(1, K+1):
        temp = math.gcd(a, b)
        for c in range(1, K+1):
            count += math.gcd(temp, c)

print(count)