Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input().split()))
list_S = [0]
ans = 0
for i in range(n):
    list_S.append(list_S[i] + a[i])

dict_S = {}
for i in list_S:
    if i in dict_S:
        dict_S[i] = 1
    else:
        dict_S[i] += 1

for v in dict_S.values():
    ans += v * (v-1) // 2

print(ans)

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
list_S = [0]
ans = 0
for i in range(n):
    list_S.append(list_S[i] + a[i])

list_S.sort()
pre = list_S[0]
acc = 1
for i in range(1,n+1):
    if list_S[i] == pre:
        acc += 1
    else:
        ans += acc * (acc-1) // 2
        pre = list_S[i]
        acc = 1

ans += acc * (acc-1) // 2

    
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]

cur = [a[0], a[1]]
now = a[0]
for i in a[2:]:
    loc = 0
    maxer = min(cur[0], cur[-1])
    for j in range(1, len(cur)):
        temp = min(cur[j - 1], cur[j])
        if temp > maxer:
            loc = j
            maxer = temp
    now += maxer
    cur = cur[:loc] + [i] + cur[loc:]

print(now)


Fixed submission:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]

if n % 3 == 0:
    if n % 2 == 0:
        print(a[0] + sum(a[1:n//2]) * 2)
    else:
        print(a[0] + sum(a[1:n//2]) * 2 + a[n//2])
elif n % 3 == 2:
    if n % 2 == 0:
        print(a[0] + sum(a[1:n//2]) * 2)
    else:
        print(a[0] + sum(a[1:n//2]) * 2 + a[n//2])
else:
    if n % 2 == 0:
        print(a[0] + sum(a[1:n//2]) * 2)
    else:
        print(a[0] + sum(a[1:n//2]) * 2 + a[n//2])
Buggy python submission (verdict: Runtime Error):
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
a = []
for i in range(1,101):
    if i not in p:
        a.append(i)

m = []
for i in range(len(a)):
    m.append(abs(a[i] - x))

miner = min(m)
res = []
for i in a:
    if abs(x - i) == miner:
        res.append(i)

print(min(res))

Fixed submission:
x, n = [int(i) for i in input().split()]
p = [int(i) for i in input().split()]
a = []
for i in range(-2,102):
    if i not in p:
        a.append(i)

m = []
for i in range(len(a)):
    m.append(abs(a[i] - x))

miner = min(m)
res = []
for i in a:
    if abs(x - i) == miner:
        res.append(i)

print(min(res))
Buggy python submission (verdict: Time Limit Exceeded):
input()
a = [int(i) for i in input().split()]

res = 1
for i in a:
    res *= i

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

Fixed submission:
input()
a = [int(i) for i in input().split()]
 
res = 1
if 0 in a:
    res = 0
else:
    for i in a:
        res *= i
        if res > 10**18:
            res = -1
            break

print(res)
Buggy python submission (verdict: Time Limit Exceeded):
a = input()

def int2019(s):
    modTable = [0] * 2019
    total = 0
    for i in range(len(s)):
        nextTable = [0] * 2019
        for j in range(2019):
            nextTable[(j * 10 + int(s[i])) % 2019] = modTable[j]

        nextTable[int(s[i]) % 2019] += 1
        total += nextTable[0]
        modTable = nextTable

    return total


print(int2019(a))


Fixed submission:
a = input()

def int2019(s):
    s = [int(i) for i in s]
    modTable = [0] * 2019
    total = 0
    for i in range(len(s)):
        nextTable = [0] * 2019
        for j in range(2019):
            nextTable[(j * 10 + (s[i])) % 2019] = modTable[j]

        nextTable[(s[i]) % 2019] += 1
        total += nextTable[0]
        modTable = nextTable

    return total


print(int2019(a))
Buggy python submission (verdict: Runtime Error):
a = int(input())
b = input()

import math

def nCr(n,r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)


R = 0
G = 0
B = 0
for i in b:
    if i == "R":
        R += 1
    elif i == "G":
        G += 1
    else:
        B += 1

res = 0
for i in range(0, len(b)):
    for k in range(i + 1, len(b)):
        if (i + k) % 2 == 0:
            if b[i] != b[k] and b[i] != b[(i + k) //2] and b[k] != b[(i + k) //2]:
                res += 1

print(nCr(R, 1) * nCr(G, 1) * nCr(B, 1) - res)

Fixed submission:
a = int(input())
b = input()

import math

def nCr(n,r):
    f = math.factorial
    return f(n) // f(r) // f(n-r)


R = 0
G = 0
B = 0
for i in b:
    if i == "R":
        R += 1
    elif i == "G":
        G += 1
    else:
        B += 1


if R == 0 or G == 0 or B == 0:
    print(0)
else:
    res = 0
    for i in range(0, len(b)):
        for k in range(i + 1, len(b)):
            if (i + k) % 2 == 0:
                if b[i] != b[k] and b[i] != b[(i + k) //2] and b[k] != b[(i + k) //2]:
                    res += 1

    print(nCr(R, 1) * nCr(G, 1) * nCr(B, 1) - res)
Buggy python submission (verdict: Runtime Error):
a, b, c = [int(i) for i in input().split()]

if a*b < (c - a - b)*(c - a - b)/4 and 4*a*b - (c - a - b)*(c - a - b) < 0:
    print("Yes")
else:
    print("No")

Fixed submission:
a, b, c = [int(i) for i in input().split()]

if c <= a + b:
    print("No")
elif 4*a*b < (c - a - b)*(c - a - b):
    print("Yes")
else:
    print("No")
Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())

x = dict()
x[0] = 0
x[1] = 1
x[2] = 2
x[3] = 3
x[4] = 4
x[5] = 5
x[6] = 5
x[7] = 4
x[8] = 3
x[9] = 2
x[10] = 1
x[11] = 2
x[12] = 3
x[13] = 4
x[14] = 5
x[15] = 6
x[16] = 6
x[17] = 5
x[18] = 4
x[19] = 3
x[20] = 2

def dp(n):
    if n in x:
        return x[n]
    else:
        if 10**len(str(n)) - n < n:
            x[n] = min(dp(10**len(str(n)) - n) + 1, int(str(n)[0]) + dp(int(str(n)[1:])))
        else:
            x[n] = int(str(n)[0]) + dp(int(str(n)[1:]))
        return x[n]

print(dp(a))

Fixed submission:
S = input()
n = len(S)
dp = [[0] * 2 for _ in range(n+1)]
 
dp[0][0] = 0
dp[0][1] = 1
for i in range(n):
    dp[i+1][0] = min(int(S[i]) + dp[i][0], 10 - int(S[i]) + dp[i][1])
    dp[i+1][1] = min(int(S[i]) + 1 + dp[i][0], 10 - int(S[i]) - 1 + dp[i][1])    
 
print(dp[n][0])
Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: student[0] + 100000000000000000000 * student[1])

maxer = 0
for i in range(len(fanwei)):
    now = -100000000000000000000
    ans = 0
    for i in fanwei[i:]:
        down = i[0]
        if down >= now:
            ans += 1
            now = i[1]
    maxer = max(ans, maxer)

print(maxer)


Fixed submission:
a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: student[0] + 100000000000000000000 * student[1])

now = -100000000000000000000
ans = 0
for i in fanwei[:]:
    down = i[0]
    if down >= now:
        ans += 1
        now = i[1]


print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: 100000000000000000000 * (1 + student[0]) + student[1])


maxer = 0
for i in range(len(fanwei)):
    now = -100000000000000000000
    ans = 0
    for i in fanwei[i:]:
        down = i[0]
        if down >= now:
            ans += 1
            now = i[1]
    maxer = max(ans, maxer)

print(maxer)


Fixed submission:
a = int(input())
fanwei = []

for i in range(a):
    one = input().split()
    one = [int(i) for i in one]
    two = [one[0] - one[1], one[0] + one[1]]
    fanwei.append(two)

fanwei = sorted(fanwei, key=lambda student: student[0] + 100000000000000000000 * student[1])

now = -100000000000000000000
ans = 0
for i in fanwei[:]:
    down = i[0]
    if down >= now:
        ans += 1
        now = i[1]


print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
b = input()
a = [i for i in b]
out = 0
for k in range(len(a)):
	for i in range(len(a) - 1):
		if a[i] == 'B' and a[i + 1] == 'W':
			out += 1
			a[i] = 'W'
			a[i + 1] = 'B'
		
print(out)

Fixed submission:
b = input()
nes = []
nowb = 0
noww = 0
counter = 0
for i in b:
	if i == 'B':
		if noww == 0:
			nowb += 1
		else:
			counter += nowb * noww
			nowb += 1
			noww = 0
	else:
		if nowb != 0:
			noww += 1
		
counter += nowb * noww

print(counter)
Buggy python submission (verdict: Time Limit Exceeded):
a = input().split()
a = [int(i) for i in a]
query = []
citydict = dict()
for i in range(a[1]):
	temp = input().split()
	temp = [int(i) for i in temp]
	query.append(temp)
	if temp[0] not in citydict:
		citydict[temp[0]] = [temp[1]]
	else:
		citydict[temp[0]].append(temp[1])
		
for i in citydict:
	citydict[i] = sorted(citydict[i])
	
for i in query:
	print ("%06d%06d" % (i[0],citydict[i[0]].index(i[1]) + 1))

Fixed submission:
a = input().split()
a = [int(i) for i in a]
query = []
citydict = dict()
for i in range(a[1]):
	temp = input().split()
	temp = [int(i) for i in temp]
	query.append(temp)
	try:
		citydict[temp[0]].append(temp[1])
	except:
		citydict[temp[0]] = [temp[1]]
		
indexdict = dict()
for i in citydict:
	citydict[i] = sorted(citydict[i])
	indexdict[i] = dict()
	for j in range(len(citydict[i])):
		indexdict[i][citydict[i][j]] = j
		
for i in query:
	print ("%06d%06d" % (i[0],indexdict[i[0]][i[1]] + 1))

Buggy python submission (verdict: Time Limit Exceeded):
a = input().split()
a = [int(i) for i in a]
query = []
citydict = dict()
for i in range(a[1]):
	temp = input().split()
	temp = [int(i) for i in temp]
	query.append(temp)
	if temp[0] not in citydict:
		citydict[temp[0]] = [temp[1]]
	else:
		citydict[temp[0]].append(temp[1])
		
for i in citydict:
	citydict[i] = sorted(citydict[i])
	
for i in query:
	print ("%06d%06d" % (i[0],citydict[i[0]].index(i[1]) + 1))

Fixed submission:
a = input().split()
a = [int(i) for i in a]
query = []
citydict = dict()
for i in range(a[1]):
	temp = input().split()
	temp = [int(i) for i in temp]
	query.append(temp)
	try:
		citydict[temp[0]].append(temp[1])
	except:
		citydict[temp[0]] = [temp[1]]
		
indexdict = dict()
for i in citydict:
	citydict[i] = sorted(citydict[i])
	indexdict[i] = dict()
	for j in range(len(citydict[i])):
		indexdict[i][citydict[i][j]] = j
		
for i in query:
	print ("%06d%06d" % (i[0],indexdict[i[0]][i[1]] + 1))
Buggy python submission (verdict: Time Limit Exceeded):
import math

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors
	

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

num = dict()
for i in prime_factors(a[1]):
	if i not in num:
		num[i] = 1
	else:
		num[i] += 1
		
ans = 1
for j in num.values():
	ans *=  (math.factorial(j + a[0] - 1)//(math.factorial(a[0] - 1)* math.factorial(j)))
	ans %= (10**9 + 7)
	
print(ans)

Fixed submission:
import math
 
def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return factors
	

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		g, y, x = egcd(b % a, a)
		return (g, x - (b // a) * y, y)
		
def modinv(a, m):
	g, x, y = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m
		
def factorial(n):
	num = 1
	while n >= 1:
		num = (num * n) % 1000000007
		n = n - 1
	return num
	   
a = input().split()
a = [int(i) for i in a]
 
num = dict()
for i in prime_factors(a[1]):
	if i not in num:
		num[i] = 1
	else:
		num[i] += 1
		
ans = 1
for j in num.values():
	ans *= factorial(j + a[0] - 1)
	ans %= (10**9 + 7)
	inv = modinv((factorial(a[0] - 1)* factorial(j)), 1000000007)
	ans *= inv
	ans %= (10**9 + 7)
	
print(ans)
Buggy python submission (verdict: Runtime Error):
a = input().split()
a = [int(i) for i in a]

if a*b % 2 == 0:
	print ('No')
else:
	print('Yes')

Fixed submission:
a = input().split()
a = [int(i) for i in a]

if a[0] * a[1] % 2 == 0:
	print ('No')
else:
	print('Yes')
Buggy python submission (verdict: Runtime Error):
if a[1]%2 == 1:
	print ((a[0]//a[1])**3)
else:
	if a[0]%a[1] < a[1] // 2:
		print ((a[0]//a[1])**3 + ((a[0]//a[1])**3))
	else:
		print ((1 + a[0]//a[1])**3 + ((a[0]//a[1])**3))

Fixed submission:
a = [int(i) for i in input().split()]
 
if a[1]%2 == 1:
	print ((a[0]//a[1])**3)
else:
	if a[0]%a[1] < a[1] // 2:
		print ((a[0]//a[1])**3 + ((a[0]//a[1])**3))
	else:
		print ((1 + a[0]//a[1])**3 + ((a[0]//a[1])**3))

Buggy python submission (verdict: Runtime Error):
from math import ceil
a = [int(i) for i in input().split()]
if a[1]%2 == 1:
	print ((a[0]//a[1])**3)
else:
	print (math.ceil(a[0]/(a[1]))**3 + ((a[0]//a[1])**3))

Fixed submission:
a = [int(i) for i in input().split()]
 
if a[1]%2 == 1:
	print ((a[0]//a[1])**3)
else:
	if a[0]%a[1] < a[1] // 2:
		print ((a[0]//a[1])**3 + ((a[0]//a[1])**3))
	else:
		print ((1 + a[0]//a[1])**3 + ((a[0]//a[1])**3))
Buggy python submission (verdict: Runtime Error):
a = input()
m = int(a[0])
n = int(a[1])

print(m*n - m - n +1)

Fixed submission:
a = input().split()
m = int(a[0])
n = int(a[1])
 
print(m*n - m - n +1)
Buggy python submission (verdict: Time Limit Exceeded):
a = input().split()
n = int(a[0])
m = int(a[1])
q = int(a[2])

table = [[] for i in range(n)]
for i in range(m):
	a = input().split()
	l = int(a[0]) - 1
	r = int(a[1]) - 1
	table[l].append(r)

		
for i in range(q):
	output = 0
	a = input().split()
	l = int(a[0]) - 1
	r = int(a[1]) - 1
	for k in range(l, r + 1):
		for j in table[k]:
			if r >= j:
				output += 1
	print (output)
	

Fixed submission:
import sys
s = sys.stdin.readlines()
 
N,M,Q = map(int,s[0].split())
 
Section = [[0]*N for _ in [0]*N]
for L,R in (map(int, e.split()) for e in s[1:M+1]):
    Section[L-1][R-1] += 1
 
Sum = [[0]*(N+1) for _ in [0]*(N+1)]
for i in range(N):
    for j in range(N):
        Sum[i+1][j+1] = Sum[i][j+1]+Sum[i+1][j]-Sum[i][j]+Section[i][j]
 
for p,q in (map(int, e.split()) for e in s[M+1:]):
    print(Sum[q][q]-Sum[p-1][q])
Buggy python submission (verdict: Runtime Error):
a = input().split()
n = int(a[0])
m = int(a[1])

a = input().split(' ')
a = [int(i) for i in a]

summatrix = [[0 for i in range(n)] for i in range(n)]
output = 0

for i in range(n):
	for j in range(i, n):
		if i != 0:
			summatrix[i][j] = (summatrix[i - 1][j - 1]%m + a[i]%m + a[j]%m)%m
		if i == 0 and j == 0:
			summatrix[0][0] = a[0] %m
		else:
			summatrix[i][j] = (summatrix[i][j - 1]%m + a[j]%m)% m
		if summatrix[i][j] == 0:
			output += 1
		
print (output)

Fixed submission:
a = input().split(' ')
m = int(a[0])
n = int(a[1])

if m%n == 0:
	print (0)
else:
	print (1)
Buggy python submission (verdict: Runtime Error):
n = int(input())
if n == 0:
	 print ("0")
out = []
while n != 0:
	 n, rem = divmod(n, -2)
	 if rem < 0:
	 	 n += 1
	 	 rem -= ^2
	 out.append(rem)
print ("".join(map(str, out[::-1])))

Fixed submission:
n = int(input())
if n == 0:
	 print ("0")
out = []
while n != 0:
	 n, rem = divmod(n, -2)
	 if rem < 0:
	 	 n += 1
	 	 rem -= -2
	 out.append(rem)
print ("".join(map(str, out[::-1])))
Buggy python submission (verdict: Runtime Error):
a, b, c, d = map(int, input().split())
ans = 0
if abs(a-c) <= d: 
    ans = 1
if abs(a-b) <= d && abs(b-c) <= d: 
    ans = 1
if ans == 1:
    print("Yes")
else
	print("No")

Fixed submission:
a, b, c, d = map(int, input().split())
ans = 0
if abs(a-c) <= d: 
    ans = 1
if abs(a-b) <= d and abs(b-c) <= d: 
    ans = 1
if ans == 1:
    print("Yes")
else:
	print("No")
Buggy python submission (verdict: Runtime Error):
x, y = map(int, input().split())
ans = x - 1
if x <= y: 
    ans++
print(ans)

Fixed submission:
x, y = map(int, input().split())
ans = x - 1
if x <= y: 
    ans = ans + 1
print(ans)
Buggy python submission (verdict: Runtime Error):
a = []
i = 0

s = int(input())

a.append(s)

while True:
    if(a[i] % 2 == 0):
        if(a[i] / 2 != 0):
        	ans = int(a[i] / 2)
        else:
            ans = 0
        if ans in a:
            print(i + 2)
            break
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(i + 2)
            break
        a.append(anss)

    i += 1

Fixed submission:
AB, BC, CA = map(int, input().split())

a = int(AB * BC / 2)

print(str(a))

Buggy python submission (verdict: Runtime Error):
a = []
i = 0

s = int(input())

a.append(s)

while True:
    if(a[i] % 2 == 0):
        if(a[i] / 2 != 0):
        	ans = int(a[i] / 2)
        else:
            ans = 0
        if ans in a:
            print(str(i + 2))
            break
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(str(i + 2))
            break
        a.append(anss)

    i += 1

Fixed submission:
AB, BC, CA = map(int, input().split())

a = int(AB * BC / 2)

print(str(a))

Buggy python submission (verdict: Runtime Error):
a = []
i = 0

s = int(input())

a.append(s)

while True:
    if(a[i] % 2 == 0):
        ans = int(a[i] / 2)
        if ans in a:
            print(str(i + 2))
            break
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(str(i + 2))
            break
        a.append(anss)

    i += 1

Fixed submission:
AB, BC, CA = map(int, input().split())

a = int(AB * BC / 2)

print(str(a))

Buggy python submission (verdict: Runtime Error):
a = []
i = 0

s = int(input())

a.append(s)

while True:
    if(a[i] % 2 == 0):
        ans = int(a[i] / 2)
        if ans in a:
            print(str(i + 2))
            break
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(str(i + 2))
            break
        a.append(anss)

    i += 1

Fixed submission:
AB, BC, CA = map(int, input().split())

a = int(AB * BC / 2)

print(str(a))

Buggy python submission (verdict: Runtime Error):
a = []
i = 0

s = int(input())

a.append(s)

while True:
    if(a[i] % 2 == 0):
        ans = int(a[i] / 2)
        if ans in a:
            print(str(i + 2))
            break
       	a.append(ans)
    else:
        anss = int(a[i] * 3 + 1)
        if anss in a:
            print(str(i + 2))
            break
        a.append(anss)

    i += 1
    
print(a)

Fixed submission:
AB, BC, CA = map(int, input().split())

a = int(AB * BC / 2)

print(str(a))
Buggy python submission (verdict: Runtime Error):
n=int(input())
k=int(input())
a=0
for i in range(n):
  x=int(input())
  a+=min(x,abs(k-x))
print(a*2)

Fixed submission:
n=int(input())
k=int(input())
a=0
for x in [int(i) for i in input().split()]:
    a+=min(x,abs(k-x))
print(a*2)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
  ans *= a
if ans > 10**18:
  print(-1)
else:
  print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
ans = 1
for a in A:
  ans *= a
  if ans > 10**18:
    print(-1)
    exit()
if ans > 10**18:
  print(-1)
else:
  print(ans)
Buggy python submission (verdict: Runtime Error):
x = int(input())
ans = []
for i in range(-105, 105):
  for j in range(-105, 105):
    if pow(i, 5) - pow(j, 5) == x:
      ans += [[i, j]]
ans = list(map(str, ans[0]))
print(" ".join(ans))
    

Fixed submission:
x = int(input())
ans = []
for i in range(-120, 120):
  for j in range(-120, 120):
    if pow(i, 5) - pow(j, 5) == x:
      ans += [[i, j]]
ans = list(map(str, ans[0]))
print(" ".join(ans))

Buggy python submission (verdict: Runtime Error):
 = int(input())
ans = []
for i in range(-105, 105):
  for j in range(-105, 105):
    if pow(i, 5) - pow(j, 5) == x:
      ans += [[i, j]]
ans = list(map(str, ans[0]))
print(" ".join(ans))
    

Fixed submission:
x = int(input())
ans = []
for i in range(-120, 120):
  for j in range(-120, 120):
    if pow(i, 5) - pow(j, 5) == x:
      ans += [[i, j]]
ans = list(map(str, ans[0]))
print(" ".join(ans))
Buggy python submission (verdict: Time Limit Exceeded):
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
abcd = sorted(abcd, key=lambda x:x[3], reverse=True)
A = [0]*N
a = 0
for i in range(2**Q):
  bag = []
  A = [-1]*(N+1)
  A[1] = 1
  ans = 0
  for j in range(Q):
    if (i>>j)&1:
      bag += [j]

  for j in bag:
    if A[abcd[j][1]] == -1:
      if A[abcd[j][0]] + abcd[j][2] <= M:
        A[abcd[j][1]] = A[abcd[j][0]] + abcd[j][2]
        ans += abcd[j][3]
      else:
        ans = 0
        break
    elif A[abcd[j][1]] == A[abcd[j][0]] + abcd[j][2]:
      ans += abcd[j][3]
    else:
      ans = 0
      break

  a = max(ans, a)

print(a)


Fixed submission:
import itertools
N, M, Q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(Q)]
A = [0]*N
ans = 0
bag = [i for i in range(1, M+1)]
for v in itertools.combinations_with_replacement(bag, N):
  an = 0
  for a, b, c, d in abcd:
    a -= 1
    b -= 1
    if v[b] - v[a] == c:
      an += d

  ans = max(ans, an)
print(ans)
Buggy python submission (verdict: Runtime Error):
 = list(input())
if '7' in n:
  print('YES')
else:
  print('NO')


Fixed submission:
n = list(input())
if '7' in n:
  print('Yes')
else:
  print('No')
Buggy python submission (verdict: Time Limit Exceeded):
import math 
k = int(input())
ans = 0 
dic = {}
for x in range(1, k+1):
  for y in range(1, k+1):
    dic[(x, y)] = math.gcd(x, y)

for x in range(1, k+1):
  for y in range(1, k+1):
    for z in range(1, k+1):
      ans += dic[(x, dic[(y, z)])]
print(ans)

Fixed submission:
import math 
k = int(input())
ans = 0 
dic = {}
for x in range(1, k+1):
  for y in range(1, k+1):
    dic[(x, y)] = math.gcd(x, y)

for x in range(1, k+1):
  for y in range(1, k+1):
    for z in range(1, k+1):
      ans += dic[(x, dic[(y, z)])]
print(ans)