Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

list = []
for i in range(n//k + 2) :
    list.append(abs(n-k))
    n = abs(n-k)

print(min(list))


Fixed submission:
n, k = map(int, input().split())

if n < k :
    if n >= abs(n-k):
        ans = abs(n-k)
    else :
        ans = n
elif n%k != 0 :
    ans = abs(n%k - k)
else :
    ans = 0

print(ans)
Buggy python submission (verdict: Runtime Error):
k,n=map(int,input().split())
a=list(map(int,input().split())
lists=[]
for i in range(N):
       d=int(a[i+1]-a[i])
       lists.append(d)
lists.append(K-a[N-1]+a[0])
ans=K-max(b)
print(ans)

Fixed submission:
k, n = map(int, input().split())
a = list(map(int, input().split()))
a2 = []
for i in range(n-1):
    d = int(a[i+1]-a[i])
    a2.append(d)
a2.append(k-a[n-1]+a[0])
ans = k - max(a2)
print(ans)

Buggy python submission (verdict: Runtime Error):
k, n = map(int, input().split())
a = list(map(int, input().split())
b = []
for i in range(N):
    d = int(a[i+1]-a[i])
    b.append(int(d))

b.append(K - a[N-1] + a[0])

ans = K - max(b)

print(ans)

Fixed submission:
k, n = map(int, input().split())
a = list(map(int, input().split()))
a2 = []
for i in range(n-1):
    d = int(a[i+1]-a[i])
    a2.append(d)
a2.append(k-a[n-1]+a[0])
ans = k - max(a2)
print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()

if S.count(A) >= 1 and S.count(B) >= 1 :
    print("Yes")
else :
    print("No")

Fixed submission:
S = input()

if S.count("A") >= 1 and S.count("B") >= 1 :
    print("Yes")
else :
    print("No")

Buggy python submission (verdict: Runtime Error):
S = input()

if S.count(A) >= 1 and S.count(B) >= 0 :
    print("Yes")
else :
    print("No")

Fixed submission:
S = input()

if S.count("A") >= 1 and S.count("B") >= 1 :
    print("Yes")
else :
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
N, A, B = map(int,input().split())

list = []
for _ in range(N):
    [list.append('b') for i in range(A)]
    [list.append('c') for j in range(B)]

a = list[:N:]
print(a.count("b"))


Fixed submission:
N, A, B = map(int,input().split())
ans = A*(N//(A+B)) + min(N%(A+B),A)
print(ans)
Buggy python submission (verdict: Runtime Error):
N,M = map(int,input().split())

ans = [-1] * N

for i in range(M):
    s,c = map(int,input().split())
    if ans[s-1] != -1 and ans[s-1] != c :
        print(-1)
        exit()
    t[s-1] = c

if N != 1 :
    if ans[0] == 0 :
        print(-1)
        exit()
    if ans[0] == -1 :
        ans[0] = 1
    for i in range(N):
        if ans[i] == -1:
            ans[i] = 0
else :
    if ans[0] == -1 :
        ans[0] = 0

print(*ans,sep='')


Fixed submission:
N,M = map(int,input().split())

ans = [-1] * N

for i in range(M):
    s,c = map(int,input().split())
    if ans[s-1] != -1 and ans[s-1] != c :
        print(-1)
        exit()
    ans[s-1] = c

if N != 1 :
    if ans[0] == 0 :
        print(-1)
        exit()
    if ans[0] == -1 :
        ans[0] = 1
    for i in range(N):
        if ans[i] == -1:
            ans[i] = 0
else :
    if ans[0] == -1 :
        ans[0] = 0

print(*ans,sep='')
Buggy python submission (verdict: Runtime Error):
n, r = int(input().split())

if n >= 10 :
    ans = r
else :
    ans = r + 100 * (10 - n)


Fixed submission:
n, r = map(int, input().split())

if n >= 10 :
    ans = r
else :
    ans = r + 100 * (10 - n)

print(ans)

Buggy python submission (verdict: Runtime Error):
n, r = int(input().split())

if n >= 10 :
    ans = r
else :
    ans = r - 100 * (10 - n)


Fixed submission:
n, r = map(int, input().split())

if n >= 10 :
    ans = r
else :
    ans = r + 100 * (10 - n)

print(ans)

Buggy python submission (verdict: Runtime Error):
n, r = int(input())

if n >= 10 :
    ans = r
else :
    ans = r - 100 * (10 - n)


Fixed submission:
n, r = map(int, input().split())

if n >= 10 :
    ans = r
else :
    ans = r + 100 * (10 - n)

print(ans)
Buggy python submission (verdict: Runtime Error):
list = [map(int, input().split())]

if a = b or b = c or a = c :
    print("Yes")
else :
    print("No")

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

if a == b != c or b == c != a or a == c != b :
    print("Yes")
else :
    print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
d = {}
for _ in range(N):
    S = input()
    if S in l :
        d[S] += 1
    else :
        d[S] = 1

m = max(d.values())

for s in sorted(k for k in d if d[k]==m) :
    print(s)


Fixed submission:
N = int(input())
d = {}
for _ in range(N):
    S = input()
    if S in d :
        d[S] += 1
    else :
        d[S] = 1

m = max(d.values())

for s in sorted(k for k in d if d[k]==m) :
    print(s)
Buggy python submission (verdict: Runtime Error):
H, A = map(int, input().split())
ans = H // A + (H % A)/(H % A) * 1
print(round(ans))


Fixed submission:
H, A = map(int, input().split())

if H % A == 0 :
    ans = H / A
else :
    ans = H // A + 1

print(round(ans))

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

ans = H // A + (H % A)/(H % A) * 1

print(ans)

Fixed submission:
H, A = map(int, input().split())

if H % A == 0 :
    ans = H / A
else :
    ans = H // A + 1

print(round(ans))
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())

h = list(map(int,input().split()))

h.sort(reverse=True)
ans = 0
if k == 0 :
    ans = sum(h)
else :
    for i in range(k):
        h[i] = 0
    print(sum(h))    


Fixed submission:
n,k = map(int,input().split())

h = list(map(int,input().split()))

h.sort(reverse=True)

if k == 0 :
    print(sum(h))
elif k <= n :
    for i in range(k):
        h[i] = 0
    print(sum(h))
else :
    print(0)

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

h = list(map(int,input().split()))

h.sort()
sumh = 0
if k == 0 :
    print(sum(h))
else :
    for i in range(1,k+1):
        sumh += h[i*-1]
    print(sum(h)-sumh)


Fixed submission:
n,k = map(int,input().split())

h = list(map(int,input().split()))

h.sort(reverse=True)

if k == 0 :
    print(sum(h))
elif k <= n :
    for i in range(k):
        h[i] = 0
    print(sum(h))
else :
    print(0)

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

h = list(map(int,input().split()))

h.sort()
sumh = 0
for i in range(1,k+1):
    sumh += h[i*-1]
print(sum(h)-sumh)


Fixed submission:
n,k = map(int,input().split())

h = list(map(int,input().split()))

h.sort(reverse=True)

if k == 0 :
    print(sum(h))
elif k <= n :
    for i in range(k):
        h[i] = 0
    print(sum(h))
else :
    print(0)
Buggy python submission (verdict: Runtime Error):
n = int(input())
l = [list(map(int, input().split())) for _ in range(n)]

sum = 0
for i in range(n):
    for j in range(n):
        if i != j:
            sum += sqrt((l[i][0] - l[j][0]) * (l[i][0] - l[j][0]) + (l[i][1] - l[j][1]) * (l[i][1] - l[j][1]))
print(sum / n)


Fixed submission:
n = int(input())
xy = [list(map(int,input().split())) for i in range(n)]

from itertools import permutations
import math
m = math.factorial(n)
per = permutations(xy,n)

d = 0
c = 0
for j in per :
    for i in range(n-1):
        d += ((j[i+1][0]-j[i][0])**2 + (j[i+1][1]-j[i][1])**2) ** 0.5

print(d/m)
Buggy python submission (verdict: Runtime Error):
s = input()

if s == "Sunny" :
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
elif :
    print("Sunny")


Fixed submission:
s = input()

if s == "Sunny" :
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
else :
    print("Sunny")

Buggy python submission (verdict: Runtime Error):
s = input()

if s == "Sunny" :
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
elif s == "Rainy"
    print("Sunny")


Fixed submission:
s = input()

if s == "Sunny" :
    print("Cloudy")
elif s == "Cloudy":
    print("Rainy")
else :
    print("Sunny")
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int,input().split())

a = [int(input()) for i in range(q)]
c = [0]*n
for i in a:
    c[i-1] += 1

for i in range(n) :
    if sum(c)-c[i] >= k :
        print("No")
    else :
        print("Yes")


Fixed submission:
n,k,q = map(int,input().split())

c = [k-q]*(n+1)

for i in range(q):
    c[int(input())] += 1

for i in range(1,n+1) :
    if c[i]>0 :
        print("Yes")
    else :
        print("No")
Buggy python submission (verdict: Runtime Error):
print(int(input(n**3)))

Fixed submission:
print(int(input())**3)

Buggy python submission (verdict: Runtime Error):
print(int(input(n**3)))

Fixed submission:
print(int(input())**3)

Buggy python submission (verdict: Runtime Error):
print(n**3)

Fixed submission:
print(int(input())**3)
Buggy python submission (verdict: Runtime Error):
n = int(input())
b = list(map(int,input().split()))

dp = [10**8]*# NOTE:

for i in range(n-1):
    if dp[i] > b[i] :
        dp[i] = b[i]
    if dp[i+1] > b[i] :
        dp[i+1] = b[i]

print(sum(dp))


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

dp = [10**8]*n

for i in range(n-1):
    if dp[i] > b[i] :
        dp[i] = b[i]
    if dp[i+1] > b[i] :
        dp[i+1] = b[i]

print(sum(dp))
Buggy python submission (verdict: Runtime Error):
n = int(input())

v = list(map(int,input().split()))

v.sort(reverse = True)

while len(v) > 1 :
    v.append((v.pop(-1) + v.pop(-2))/2)
    v.sort(reverse = True)

print(v)


Fixed submission:
n = int(input())

v = list(map(int,input().split()))

v.sort(reverse = True)

while len(v) > 1 :
    v.append((v.pop(-1) + v.pop(-1))/2)
    v.sort(reverse = True)

print(v[0])
Buggy python submission (verdict: Runtime Error):
a, b = map(int(input().split()))

print(max(a+b, a-b, a*b))

Fixed submission:
a, b = map(int,input().split())
print(max(a+b, a-b, a*b))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

s = [input() for _ in range(n)]

for i in range(n):
    s[i] = sorted(s[i])
    s[i] = "".join(s[i])

s = sorted(s)

c = []
for j in range(n):
    if j == 0 :
        c.append(s.count(s[0]))
    else :
        c.append(s.count(s[j]))
        if s[j] == s[j-1] :
            c[j] = 0

ans = 0
for k in range(n):
    ans += c[k]*(c[k]-1)//2

print(ans)


Fixed submission:
n = int(input())

s = [input() for _ in range(n)]

for i in range(n):
    s[i] = sorted(s[i])
    s[i] = "".join(s[i])

t = {}
for i in range(n):
    if s[i] in t :
        t[s[i]] += 1
    else :
        t[s[i]] = 1

print(sum(t[k]*(t[k]-1)//2 for k in t))
Buggy python submission (verdict: Runtime Error):
n = int(input())

if n == 100000 :
    ans = 101009
elif 10000 <= n <= 99999 :
    ans = n - 10000 + 1 + 1000 + 9
elif 1000 <= n <= 9999 :
    ans = 1009
elif 100 <= n <= 999 :
    ans = n - 100 + 1 + 9
elif 10 <= n < 99 :
    ans = 9 
elif 1 <= n <= 9 :
    ans = n

print(ans)


Fixed submission:
n = int(input())
c = 0
for i in range(1,n+1):
    if len(str(i)) % 2 == 1 :
        c += 1

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

if (a+b)%2 == 0 :
    print((a+b)/2))
else :
    print("IMPOSSIBLE")


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

if (a+b)%2 == 0 :
    print((a+b)//2)
else :
    print("IMPOSSIBLE")

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

if (a+b)%2 == 0 :
    print(a+b)/2))
else :
    print("IMPOSSIBLE")


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

if (a+b)%2 == 0 :
    print((a+b)//2)
else :
    print("IMPOSSIBLE")
Buggy python submission (verdict: Time Limit Exceeded):
L,R = map(int,input().split())

ans = 3000

if R-L >= 2100 :
    ans = 0

for i in range(L,R):
    for j in range(L+1,R+1):
        if (i*j)%2019 < ans :
            ans = (i*j)%2019
            if ans == 0 :
                break

print(ans)


Fixed submission:
L,R = map(int,input().split())

if R-L >= 2100 :
    ans = 0
else :
    ans = 2019
    for i in range(L,R):
        for j in range(i+1,R+1):
            if (i*j)%2019 < ans :
                ans = (i*j)%2019
                if ans == 0 :
                    break

print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())
t = set[s]
if len(t) == 2 and s.count(t[0]) == 2 :
    print("Yes")
else :
    print("No")


Fixed submission:
s = list(input())
t = list(set(s))
if len(t) == 2 and s.count(t[0]) == 2 :
    print("Yes")
else :
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
a,b,c,d = map(int,input().split())
ans = 0
for i in range(a,b+1):
    if i%c != 0 and i%d != 0 :
        ans += 1

print(ans)


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

import math

bc = b//c
bd = b//d
bcd = b//(c*d//math.gcd(c,d))

ac = (a-1)//c
ad = (a-1)//d
acd = (a-1)//(c*d//math.gcd(c,d))

ans = (b-bc-bd+bcd)-((a-1)-ac-ad+acd)

print(ans)
Buggy python submission (verdict: Runtime Error):
N, X = map(int, input().split())
L = list(map(int, input().split()))

c = 1
d = 0
for x in L:
    d = d + x
    if d <= X :
        ans += 1

print(ans)

Fixed submission:
N, X = map(int, input().split())
L = list(map(int, input().split()))

ans = 1
d = 0
for x in L:
    d = d + x
    if d <= X :
        ans += 1

print(ans)
Buggy python submission (verdict: Runtime Error):
n,m = map(int,input().split())
lr = [[map(int,input().split())] for i in range(m)]

max = 0
min = n+1
for i in range(m):
    if lr[i][0] > max :
        max = lr[i][0]
    if lr[i][1] < min :
        min = lr[i][1]

print(min-max+1)


Fixed submission:
n,m = map(int,input().split())
lr = [list(map(int,input().split())) for i in range(m)]

max = 0
min = n+1
for i in range(m):
    if lr[i][0] > max :
        max = lr[i][0]
    if lr[i][1] < min :
        min = lr[i][1]

if min-max >= 0:
    print(min-max+1)
else :
    print(0)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input())
print(max(a,b)*2 -1)


Fixed submission:
a,b = map(int,input().split())
if a != b :
    print(max(a,b)*2 -1)
else :
    print(a*2)
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

l = []
l.append(a)
l.append(b)
l.append(c)
l.append(d)
l.append(e)
ans = 0
for i in range(5):
    for j in range(i+1,5):
        if l[j] - l[i] > k :
            ans += 1

if ans = 0 :
    print("Yay!")
else :
    print(":(")


Fixed submission:
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
k = int(input())

l = []
l.append(a)
l.append(b)
l.append(c)
l.append(d)
l.append(e)
ans = 0
for i in range(5):
    for j in range(i+1,5):
        if l[j] - l[i] > k :
            ans += 1

if ans == 0 :
    print("Yay!")
else :
    print(":(")
Buggy python submission (verdict: Runtime Error):
l = []
for i in range(5):
    l.append(int(input()))
amari = []
for i in range(5):
    amari.append(10-l[i]%10)
jikan = []
for i in range(5):
    jikan.append(l[i] + amari[i])
print(sum[jikan]-max(amari))


Fixed submission:
l = []
for i in range(5):
    l.append(int(input()))
amari = []
for i in range(5):
    if 10-l[i]%10 == 10 :
        amari.append(0)
    else :
        amari.append(10-l[i]%10)
jikan = []
for i in range(5):
    if amari[i] == 10:
        jikan.append(l[i])
    else :
        jikan.append(l[i] + amari[i])

print(sum(jikan)-max(amari))
Buggy python submission (verdict: Runtime Error):
S = input()

c = 0
l = []
for i in range(len(S)):
    if S[i] == "A" or S[i] == "C" :
        c += 1
    elif S[i] == "G" or S[i] == "T" :
        c += 1
    else :
        l.append(c)
        c = 0

print(max(l))


Fixed submission:
S = input()

c = 0
m = 0

for i in range(len(S)):
    if S[i] == "A" or S[i] == "C" :
        c += 1
        m = max(c,m)
    elif S[i] == "G" or S[i] == "T" :
        c += 1
        m = max(c,m)
    else :
        m = max(c,m)
        c = 0

print(m)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = set(int(input()) for i in range(n))
kami = []
a.sort()
for i in range(n) :
    if i in kami :
        kami.remove(i)
    else :
        kami.add(i)

print(len(kami))


Fixed submission:
n = int(input())
kami = set()

for i in range(n) :
    a = int(input())
    if a in kami :
        kami.remove(a)
    else :
        kami.add(a)

print(len(kami))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

kami = []

for i in range(n) :
    a = int(input())
    if a in kami :
        kami.remove(a)
    else :
        kami.append(a)

print(len(kami))


Fixed submission:
n = int(input())
kami = set()

for i in range(n) :
    a = int(input())
    if a in kami :
        kami.remove(a)
    else :
        kami.add(a)

print(len(kami))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(int(input()) for i in range(n))
kami = []
a.sort()
for i in a :
    if i in kami :
        kami.remove(i)
    else :
        kami.append(i)

print(len(kami))


Fixed submission:
n = int(input())
kami = set()

for i in range(n) :
    a = int(input())
    if a in kami :
        kami.remove(a)
    else :
        kami.add(a)

print(len(kami))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(int(input()) for i in range(n))
kami = []
a.sort()
for i in a :
    if i in kami :
        kami.remove(i)
    else :
        kami.append(i)

print(len(kami))


Fixed submission:
n = int(input())
kami = set()

for i in range(n) :
    a = int(input())
    if a in kami :
        kami.remove(a)
    else :
        kami.add(a)

print(len(kami))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(int(input()) for i in range(n))
kami = []

for i in a :
    if i in kami :
        kami.remove(i)
    else :
        kami.append(i)
    kami.sort()

print(len(kami))


Fixed submission:
n = int(input())
kami = set()

for i in range(n) :
    a = int(input())
    if a in kami :
        kami.remove(a)
    else :
        kami.add(a)

print(len(kami))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(int(input()) for i in range(n))
kami = []

c = 0
for i in range(n) :
    if a.count(a[i]) % 2 == 1:
        c += 1

print(c)


Fixed submission:
n = int(input())
kami = set()

for i in range(n) :
    a = int(input())
    if a in kami :
        kami.remove(a)
    else :
        kami.add(a)

print(len(kami))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(int(input()) for i in range(n))
kami = []

for i in a :
    if i in kami :
        kami.remove(i)
    else :
        kami.append(i)

print(len(kami))


Fixed submission:
n = int(input())
kami = set()

for i in range(n) :
    a = int(input())
    if a in kami :
        kami.remove(a)
    else :
        kami.add(a)

print(len(kami))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
b = []
for i in range(n):
    b.append(a[i])
    b.reverse()

print(*b,sep=' ')


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

b = [0] * n

if n % 2 == 0 :
    c = n//2 - 1
else :
    c = n // 2

b[c] = a[0]

for i in range(1,n) :
    if i % 2 == 1 :
        b[c + i] = a[i]
        c += i
    else :
        b[c - i] = a[i]
        c -= i

if c != 0 :
    b.reverse()
    print(*b,sep=" ")
else :
    print(*b,sep=" ")
Buggy python submission (verdict: Time Limit Exceeded):
k, s = map(int, input().split())
ans = 0
for x in range(k+1):
    for y in range(k+1):
        for z in range(k+1):
            if x+y+z==s :
                ans += 1
print(ans)

Fixed submission:
k, s = map(int, input().split())
ans = 0
for x in range(k+1):
    for y in range(k+1):
        z = s - x - y
        if 0 <= z <= k :
            ans += 1
print(ans)
Buggy python submission (verdict: Runtime Error):
s = list(input())
n = len(s)

ans = 0
for i in range(2**(n-1)) :
    wa = 0
    kou = s[0]
    for j in range(n-1):
        if i>>j & 1 :
            wa += int(kou)
            kou = s[j+1]
        else :
            kou += s[j+1]
        if j == n-2 :
            wa += int(kou)
    ans += wa
if n == 1 :
    print(int(s))
else :
    print(ans)

Fixed submission:
s = input()
n = len(s)

ans = 0
for i in range(2**(n-1)) :
    wa = 0
    kou = s[0]
    for j in range(n-1):
        if i>>j & 1 :
            wa += int(kou)
            kou = s[j+1]
        else :
            kou += s[j+1]
        if j == n-2 :
            wa += int(kou)
    ans += wa
if n == 1 :
    print(int(s))
else :
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
*A, = map(int, input().split())

ans = 1
for i in range(N):
    ans = ans * A[i]

if ans>10**18:
    print(-1)
    exit()
print(ans)

Fixed submission:
N = int(input())
*A, = map(int, input().split())

def dfs(l, r):

    if l==r:
        return A[l]
    mid = (l+r)//2
    ans = 1
    ans = ans * dfs(l, mid)
    ans = ans * dfs(mid+1, r)
    return ans

ans = dfs(0, len(A)-1)

if ans>10**18:
    print(-1)
    exit()
print(ans)
Buggy python submission (verdict: Runtime Error):

List = []
def dfs(S):
    global N,M

    if len(S)==N:
        List.append(list(map(int, list(S))))
        return
    for i in range(1, M+1, 1):
        i = str(i)
        dfs(S+i)
    return

N,M,Q = map(int, input().split())
L = []

dfs("")
for i in range(1,M+1,1):
    L.append(i)

A = []
B = []
C = []
D = []
for _ in range(Q):
    a,b,c,d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

ans = 0
for l in List:
    temp = 0
    for q in range(Q):
        if (l[B[q]-1]-l[A[q]-1])==C[q]:
            temp = temp + D[q]
    ans = max(ans, temp)
print(ans)
            

Fixed submission:
import itertools

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,M,Q = map(int, input().split())
L = []

for i in range(1,M+1,1):
    L.append(i)

A = []
B = []
C = []
D = []
for _ in range(Q):
    a,b,c,d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

List = list(itertools.combinations_with_replacement(L, N))
ans = 0
for l in List:
    temp = 0
    for q in range(Q):
        if (l[B[q]-1]-l[A[q]-1])==C[q]:
            temp = temp + D[q]
    ans = max(ans, temp)
print(ans)

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

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,M,Q = map(int, input().split())
L = []

for i in range(1,M+1,1):
    for j in range(N):
        L.append(i)

A = []
B = []
C = []
D = []
for _ in range(Q):
    a,b,c,d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

List = list(itertools.combinations(L, N))
ans = 0
for l in List:
    temp = 0
    for q in range(Q):
        if (l[B[q]-1]-l[A[q]-1])==C[q]:
            temp = temp + D[q]
    ans = max(ans, temp)
print(ans)
            

Fixed submission:
import itertools

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N,M,Q = map(int, input().split())
L = []

for i in range(1,M+1,1):
    L.append(i)

A = []
B = []
C = []
D = []
for _ in range(Q):
    a,b,c,d = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)
    D.append(d)

List = list(itertools.combinations_with_replacement(L, N))
ans = 0
for l in List:
    temp = 0
    for q in range(Q):
        if (l[B[q]-1]-l[A[q]-1])==C[q]:
            temp = temp + D[q]
    ans = max(ans, temp)
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math

K = int(input())

sum = 0
for a in range(1, K+1, 1):
    for b in range(1, K+1, 1):
        for c in range(1, K+1, 1):
            sum = sum + math.gcd(a, math.gcd(b, c))
print(sum)


Fixed submission:
import math

K = int(input())

sum = 0
            
for a in range(1, K+1, 1):
    for b in range(1, K+1, 1):
        tmp = math.gcd(a,b)
        for c in range(1, K+1, 1):
            sum = sum + math.gcd(tmp, c)
print(sum)