qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import itertools

N, M, Q = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(Q)]

Mls = list(range(1,M+1))
Mls = [str(n) for n in Mls]
l = list(itertools.combinations_with_replacement("".join(Mls),N))

ans = 0
for i in l:
    pnt = 0
    for l in ls:
        if int(i[l[1]-1])-int(i[l[0]-1]) == l[2]:
            pnt += l[3]
    ans = max(ans,pnt)
print(ans)

Fixed code:
import itertools

N, M, Q = map(int,input().split())
ls = [list(map(int,input().split())) for i in range(Q)]

Mls = list(range(1,M+1))
Mls = [str(n) for n in Mls]
l = list(itertools.combinations_with_replacement(Mls,N))

ans = 0
for A in l:
    pnt = 0
    for l in ls:
        if int(A[l[1]-1])-int(A[l[0]-1]) == l[2]:
            pnt += l[3]
    ans = max(ans,pnt)
print(ans)
Buggy code:
import itertools;n,m,q,*l=map(int,open(0).read().split());print(max(sum(d for a,b,c,d in l[::4]if i[b-1]-i[a-1]==c)for i in itertools.combinations_with_replacement(range(m),n)))

Fixed code:
import itertools;n,m,q,*l=map(int,open(0).read().split());print(max(sum(d for a,b,c,d in[l[j*4:j*4+4]for j in range(q)]if i[b-1]-i[a-1]==c)for i in itertools.combinations_with_replacement(range(m),n)))
Buggy code:
import itertools
N, M, Q = map(int, input().split())
a = [int(input()) for _ in range(Q)]
b = [int(input()) for _ in range(Q)]
c = [int(input()) for _ in range(Q)]
d = [int(input()) for _ in range(Q)]
for i in range (Q):
     a[i], b[i], c[i], d[i] = map(int, input().split())
ans = 0
for A in combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    for i in range(Q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            tmp += d[i]
    ans = max(ans, tmp)
print(ans)

Fixed code:
import itertools
N, M, Q = map(int, input().split())
a = [0]*Q
b = [0]*Q
c = [0]*Q
d = [0]*Q
for i in range(Q):
     a[i], b[i], c[i], d[i] = map(int, input().split())
ans = 0
for A in itertools.combinations_with_replacement(range(1, M+1), N):
    tmp = 0
    for i in range(Q):
        if A[b[i]-1] - A[a[i]-1] == c[i]:
            tmp += d[i]
    ans = max(ans, tmp)
print(ans)
Buggy code:
mport itertools
def main():
    N, M, Q = map(int, input().split())
    abcd = []
    for _ in range(Q):
        a, b, c, d = map(int, input().split())
        abcd.append((a-1, b-1, c, d))
    score = 0
    for ones in list(itertools.combinations([i for i in range(N+M-1)], M-1)):
        temp = [0] * (N + M -1)
        for idx in ones:
            temp[idx] = 1
        A = [0] * N
        idx = 0
        sum_ = 0
        for i in temp:
            if i == 0:
                A[idx] = sum_ + 1
                idx += 1
            else:
                sum_ += 1
        score_temp = get_score(A, abcd)
        if score_temp > score:
            score = score_temp
    print(score)
            

def get_score(A, abcd):
    score = 0
    for a, b, c, d in abcd:
        if A[b] - A[a] == c:
            score += d
    return score

if __name__ == '__main__':
    main()

Fixed code:
import itertools
def main():
    N, M, Q = map(int, input().split())
    abcd = []
    for _ in range(Q):
        a, b, c, d = map(int, input().split())
        abcd.append((a-1, b-1, c, d))
    score = 0
    for ones in list(itertools.combinations([i for i in range(N+M-1)], M-1)):
        temp = [0] * (N + M -1)
        for idx in ones:
            temp[idx] = 1
        A = [0] * N
        idx = 0
        sum_ = 0
        for i in temp:
            if i == 0:
                A[idx] = sum_ + 1
                idx += 1
            else:
                sum_ += 1
        score_temp = get_score(A, abcd)
        if score_temp > score:
            score = score_temp
    print(score)
            
def get_score(A, abcd):
    score = 0
    for a, b, c, d in abcd:
        if A[b] - A[a] == c:
            score += d
    return score

if __name__ == '__main__':
    main()
Buggy code:
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(q)]
import itertools

A = []
M = []
for i in range(1, m+1):
    M.append(i)
for team in itertools.combinations(M, n):
    A.append(team)
    
B = [0]*len(A)
for i in range(q):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    for j in range(len(A)):
        if A[j][b-1] - A[j][a-1] == c:
            B[j] += d

print(B)

Fixed code:
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for i in range(q)]
import itertools

A = []
M = []
for i in range(1, m+1):
    M.append(i)
for team in itertools.combinations_with_replacement(M, n):
    A.append(team)
    
B = [0]*len(A)
for i in range(q):
    a = abcd[i][0]
    b = abcd[i][1]
    c = abcd[i][2]
    d = abcd[i][3]
    for j in range(len(A)):
        if A[j][b-1] - A[j][a-1] == c:
            B[j] += d

print(max(B))
Buggy code:
import itertools
s=list(map(int,input().split()))
t=[list(map(int,input().split())) for i in range(s[2])]
li=[x for x in range(1,s[0]+1)]
lity=list(itertools.combinations_with_replacement(li,s[0]))
ans=0
for k in lity:
  vmax=0
  for l in t:
    if k[l[1]-1]-k[l[0]-1]==l[2]:
      vmax+=l[3]
  ans=max(ans,vmax)
print(ans)

Fixed code:
import itertools
s=list(map(int,input().split()))
t=[list(map(int,input().split())) for i in range(s[2])]
li=[x for x in range(1,s[1]+1)]
lity=list(itertools.combinations_with_replacement(li,s[0]))
ans=0
for k in lity:
  vmax=0
  for l in t:
    if k[l[1]-1]-k[l[0]-1]==l[2]:
      vmax+=l[3]
  ans=max(ans,vmax)
print(ans)
Buggy code:
import itertools

n, m, q = map(int, input().split())
abcd = []
a_pre = [] 


for i in range(q):
  abcd.append(list(map(int, input().split())))

lis = [i for i in range(1,m+1)]
for pair in itertools.combinations(lis, n):
  a_pre.append(list(pair))

sum = 0
for i in range(len(a_pre)):
  sum_pre = 0
  for j in range(len(abcd)):
    if (a_pre[i][abcd[j][1] - 1] - a_pre[i][abcd[j][0] - 1]) == abcd[j][2]:
      sum_pre += abcd[j][3]
  if sum_pre > sum:
    sum = sum_pre

print(sum)

Fixed code:
import itertools

n, m, q = map(int, input().split())
abcd = []
a_pre = [] 


for i in range(q):
  abcd.append(list(map(int, input().split())))

lis = [i for i in range(1, m + 1)]
for pair in itertools.combinations_with_replacement(lis, n):
  a_pre.append(list(pair))

sum = 0
for i in range(len(a_pre)):
  sum_pre = 0
  for j in range(len(abcd)):
    if a_pre[i][abcd[j][1] - 1] - a_pre[i][abcd[j][0] - 1] == abcd[j][2]:
      sum_pre = sum_pre + abcd[j][3]
  if sum_pre > sum:
    sum = sum_pre

print(sum)
Buggy code:
from itertools import combinations_with_replacement
n,m,q=map(int,input().split())
l=list(combinations_with_replacement(range(1,m+1),n))

res=0
lt=[list(map(int,input().split())) for _ in range(q)]

for j in range(len(l)):
    tmp=0
    for i in range(len(lt)):
        a,b,c,d = lt[i][0],lt[i][1],lt[i][2],lt[i][3]
        if l[j][b-1]-l[j][a-1] == c:
            tmp += d
    print(tmp)
    res=max(tmp,res)

print(res)


Fixed code:
from itertools import combinations_with_replacement
n,m,q=map(int,input().split())
l=list(combinations_with_replacement(range(1,m+1),n))

res=0
lt=[list(map(int,input().split())) for _ in range(q)]

for j in range(len(l)):
    tmp=0
    for i in range(len(lt)):
        a,b,c,d = lt[i][0],lt[i][1],lt[i][2],lt[i][3]
        if l[j][b-1]-l[j][a-1] == c:
            tmp += d
    res=max(tmp,res)

print(res)
Buggy code:
import itertools
n, m, q = list(map(input().split()))
sets = [list(map(int,input().split())) for i in range(q)]
mx = 0
nums = list(range(1,11))
for h in itertools.combinations_with_replacement(nums,10):
    mxtemp = 0
    for j in range(q):
        a = sets[q][0]
        b = sets[q][1]
        if list(h)[b-1] - list(h)[a-1] == sets[q][2]:
            mxtemp += sets[q][3]
        if mxtemp > mx:
            mx = mxtemp
print(mx)

Fixed code:
import itertools
n, m, q = list(map(int,input().split()))
sets = [list(map(int,input().split())) for i in range(q)]
#print(sets)
mx = 0
nums = list(range(1,m+1))
for h in itertools.combinations_with_replacement(nums,n):
    mxtemp = 0
    for j in range(q):
        a = sets[j][0]
        b = sets[j][1]
        if list(h)[b-1] - list(h)[a-1] == sets[j][2]:
            mxtemp += sets[j][3]
    if mxtemp > mx:
        mx = mxtemp
print(mx)
Buggy code:
import itertools


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

a = [None] * Q
b = [None] * Q
c = [None] * Q
d = [None] * Q

for i in range(Q):
    num = list(map(int, input().split()))
    a[i], b[i], c[i], d[i] = num[0] - 1, num[1] - 1, num[2], num[3]

A = [i for i in range(1, M + 1)]
max_v = 0
for v in itertools.combinations(A, N):
    tmp_sum = 0
    for i in range(Q):
        if v[b[i]] - v[a[i]] == c[i]:
            tmp_sum += d[i]
    max_v = max(max_v, tmp_sum)

print(max_v)


Fixed code:
import itertools


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

a = [None] * Q
b = [None] * Q
c = [None] * Q
d = [None] * Q

for i in range(Q):
    num = list(map(int, input().split()))
    a[i], b[i], c[i], d[i] = num[0] - 1, num[1] - 1, num[2], num[3]

A = [i for i in range(1, M + 1)]

max_v = 0
for v in itertools.combinations_with_replacement(A, N):
    tmp_sum = 0
    for i in range(Q):
        if v[b[i]] - v[a[i]] == c[i]:
            tmp_sum += d[i]
    max_v = max(max_v, tmp_sum)

print(max_v)
Buggy code:
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M, Q = il()
    abcd = [il() for _ in range(Q)]

    ret = 0
    for i in itertools.combinations(range(1, M + 1), N):
        tmp = 0
        for a, b, c, d in abcd:
            if i[b - 1] - i[a - 1] == c: tmp += d

        ret = max(ret, tmp)

    print(ret)


if __name__ == '__main__':
    main()


Fixed code:
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


def f(A, B, x):
    return math.floor(A * x / B) - A * math.floor(x / B)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, M, Q = il()
    abcd = [il() for _ in range(Q)]

    ret = 0
    for i in itertools.combinations_with_replacement(range(1, M + 1), N):
        tmp = 0
        for a, b, c, d in abcd:
            if i[b - 1] - i[a - 1] == c: tmp += d

        ret = max(ret, tmp)

    print(ret)


if __name__ == '__main__':
    main()
Buggy code:
#c
import itertools

n, m, q = map(int, input().split())
lslist = []

for i in range(q):
    a, b, c, d = map(int, input().split())
    lslist.append([a, b, c, d])
print(lslist)

# n=3
# m=4
# q=3
# ls1 = [1, 3, 3, 100]
# ls2 = [1, 2, 2, 10]
# ls3 = [1, 1, 0, 1000]
# lslist = [ls1, ls2, ls3]

acomn = list(itertools.combinations_with_replacement(list(range(m)), n))

def tensu(ls, a):
    if a[ls[1]-1] - a[ls[0]-1] == ls[2]:
        return ls[3]
    else:
        return 0

def tensu2(lslist, a):
    return sum(list(map(lambda x: tensu(x, a), lslist)))

print(max(list(map(lambda a: tensu2(lslist, a), acomn))))

Fixed code:
#c
import itertools

n, m, q = map(int, input().split())
lslist = []

for i in range(q):
    a, b, c, d = map(int, input().split())
    lslist.append([a, b, c, d])

# n=3
# m=4
# q=3
# ls1 = [1, 3, 3, 100]
# ls2 = [1, 2, 2, 10]
# ls3 = [1, 1, 0, 1000]
# lslist = [ls1, ls2, ls3]

acomn = list(itertools.combinations_with_replacement(list(range(m)), n))

def tensu(ls, a):
    if a[ls[1]-1] - a[ls[0]-1] == ls[2]:
        return ls[3]
    else:
        return 0

def tensu2(lslist, a):
    return sum(list(map(lambda x: tensu(x, a), lslist)))

print(max(list(map(lambda a: tensu2(lslist, a), acomn))))
Buggy code:
n,m,q = map(int,input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
    a[i], b[i], c[i], d[i]= map(int, input().split())

s = [1] * n
#st[b[i]] - st[a[i]]  = c[i]
num = n-1
ans1 = [0] * 1000000
ans = 0
t = 0

while(s[0] != m):

    for i in range(q):
        if s[b[i]-1] - s[a[i]-1]  == c[i]:
            ans += d[i-1]
    print(ans)

    ans1[t] = ans
    t += 1
    ans = 0

    if s[num] < m:
        s[num] += 1
    elif num > 0 :
        num -= 1
        temp = s[num]+1
        if temp < m:
            for i in range(num,n):
                s[i] = temp
        else:
            while(s[num] == m):
                num -= 1
            temp = s[num]+1
            for i in range(num,n):
                s[i] = temp

        num = n-1

    print(s)




print(max(ans1))


Fixed code:
n,m,q = map(int,input().split())
a = [0] * q
b = [0] * q
c = [0] * q
d = [0] * q
for i in range(q):
    a[i], b[i], c[i], d[i]= map(int, input().split())

s = [1] * n
#st[b[i]] - st[a[i]]  = c[i]
num = n-1
#ans1 = [0] * 10000000
ans = 0
pre_ans = 0
t = 0

while(s[0] != m ):

    for i in range(q):
        if s[b[i]-1] - s[a[i]-1]  == c[i]:
            ans += d[i]
    #print(s)
    #print(ans)
    ans = max(pre_ans,ans)
    pre_ans = ans
    #t += 1

    ans = 0

    if s[num] < m:
        s[num] += 1
    elif num > 0 :
        num -= 1
        temp = s[num]+1
        if temp < m:
            for i in range(num,n):
                s[i] = temp
        else:
            while(s[num] == m):
                num -= 1
            temp = s[num]+1
            for i in range(num,n):
                s[i] = temp

        num = n-1

for i in range(q):
    if s[b[i]-1] - s[a[i]-1]  == c[i]:
        ans += d[i]

ans = max(pre_ans,ans)

print(ans)
Buggy code:
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations_with_replacement
#from fractions import gcd
from math import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

def main():
    n, m, q = map(int, input().split())
    abcd = [None] * q
    for i in range(q):
        abcd[i] = tuple(map(int, input().split()))

    A = list(range(m))
    ans = 0
    comb = list(combinations_with_replacement(A, n))
    for c in comb:
        tmp_ans = 0
        for i in range(q):
            if c[abcd[i][1]-1] - c[abcd[i][0]-1] == abcd[i][2]:
                tmp_ans += abcd[i][3]
                print(tmp_ans)
        ans = max(ans, tmp_ans)
    print(ans)

if __name__ == '__main__':
    main()



Fixed code:
#!/usr/bin/env python
import sys
from collections import Counter
from itertools import permutations, combinations_with_replacement
#from fractions import gcd
from math import gcd
from math import ceil, floor
import bisect
sys.setrecursionlimit(10 ** 6)
inf = float("inf")

def input():
    return sys.stdin.readline()[:-1]

def main():
    n, m, q = map(int, input().split())
    abcd = [None] * q
    for i in range(q):
        abcd[i] = tuple(map(int, input().split()))

    A = list(range(m))
    ans = 0
    comb = list(combinations_with_replacement(A, n))
    for c in comb:
        tmp_ans = 0
        for i in range(q):
            if c[abcd[i][1]-1] - c[abcd[i][0]-1] == abcd[i][2]:
                tmp_ans += abcd[i][3]
        ans = max(ans, tmp_ans)
    print(ans)

if __name__ == '__main__':
    main()
Buggy code:
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
cond = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    cond.append((a, b, c, d))


def calc(l):
    score = 0
    for a, b, c, d in cond:
        if l[b] - l[a] == c:
            score += d
    return score


ans = 0
l = [0] * n
l[0] = 1


def dfs(l_len):
    if l_len == n:
        ans = max(ans, calc(l))
        return

    for i in range(l[l_len - 1], m + 1):
        l[l_len] = i
        dfs(l_len + 1)


dfs(0)
print(ans)


Fixed code:
from itertools import combinations_with_replacement

n, m, q = map(int, input().split())
cond = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a -= 1
    b -= 1
    cond.append((a, b, c, d))


def calc(l):
    score = 0
    for a, b, c, d in cond:
        if l[b] - l[a] == c:
            score += d
    return score


ans = 0
l = [0] * n
l[0] = 1


def dfs(l_len):
    global l, ans
    if l_len == n:
        ans = max(ans, calc(l))
        return

    for i in range(l[l_len - 1], m + 1):
        l[l_len] = i
        dfs(l_len + 1)


dfs(1)
print(ans)
Buggy code:
import sys
import itertools

N,M,Ql = map(int, sys.stdin.readline().strip().split())
Q = []
for _ in range(Ql):
    Q.append(list(map(int, sys.stdin.readline().strip().split())))

max = 0
for A in itertools.combinations(range(1,M+1), N):
    ans = 0
    for Qi in Q:
        # print(A)
        # print(Qi)
        a,b,c,d = Qi

        if (A[b-1] - A[a-1]) == c:
            ans += d
        # print(ans)
    print()
    if max < ans:
        max = ans

print(max)


Fixed code:
import sys
import itertools

N,M,Ql = map(int, sys.stdin.readline().strip().split())
Q = []
for _ in range(Ql):
    Q.append(list(map(int, sys.stdin.readline().strip().split())))

max = 0
for A in itertools.combinations_with_replacement(range(1,M+1), N):
    ans = 0
    for Qi in Q:
        a,b,c,d = Qi

        if (A[b-1] - A[a-1]) == c:
            ans += d
    if max < ans:
        max = ans

print(max)
Buggy code:
import itertools
N, M, Q = map(int, input().split())
tapple = []
d_sum_max = 0
for i in range(Q):
    tapple.append([int(n) for n in input().split()])

A = list(itertools.product(range(1,M+1), repeat=N))
for j in range(len(A)):
    d_sum = 0
    for i in range(Q):
        if A[j][tapple[i][1]-1] - A[j][tapple[i][0]-1] == tapple[i][2]:
            d_sum += tapple[i][3] 
    if d_sum_max < d_sum:
        d_sum_max = d_sum
        
print(d_sum_max)

Fixed code:
import itertools
N, M, Q = map(int, input().split())
tapple = []
d_sum_max = 0
for i in range(Q):
    tapple.append([int(n) for n in input().split()])
A = list(itertools.combinations_with_replacement(range(1, M+1), N))
for j in range(len(A)):
    d_sum = 0
    for i in range(Q):
        if A[j][tapple[i][1]-1] - A[j][tapple[i][0]-1] == tapple[i][2]:
            d_sum += tapple[i][3] 
    if d_sum_max < d_sum:
        d_sum_max = d_sum
print(d_sum_max)
Buggy code:
n, m, q = [int(e) for e in input().split()]

import itertools as it
abcd=list()
for i in range(q):
    abcd.append([int(e) for e in input().split()])


all = it.combinations(range(1,m+1),n)

count=list()
num=0
for i in all:
    for j in abcd:
        if i[j[1]-1]-i[j[0]-1] == j[2]:
            num += j[3]
        else:
            pass
    count.append(num)
    num=0



print(max(count))

Fixed code:
n, m, q = [int(e) for e in input().split()]

import itertools as it
abcd=list()
for i in range(q):
    abcd.append([int(e) for e in input().split()])


all = it.combinations_with_replacement(range(1,m+1),n)

count=list()
num=0
for i in all:
    for j in abcd:
        if i[j[1]-1]-i[j[0]-1] == j[2]:
            num += j[3]
        else:
            pass
    count.append(num)
    num=0

print(max(count))
Buggy code:
import itertools

n, m, q = map(int, input().split())
abcd = [tuple(map(int, input().split())) for _ in range(Q)]
ans = 0
for com in itertools.combinations_with_replacement(range(1, M + 1), N):
    score = sum([d for a, b, c, d in abcd if com[b-1] - com[a-1] == c])
    if ans < score:
        ans = score
print(ans)


Fixed code:
import itertools

n, m, q = map(int, input().split())
abcd = [tuple(map(int, input().split())) for _ in range(q)]
ans = 0
for com in itertools.combinations_with_replacement(range(1, m + 1), n):
    score = sum([d for a, b, c, d in abcd if com[b-1] - com[a-1] == c])
    if ans < score:
        ans = score
print(ans)
Buggy code:

list = [0]*Q
res = 0


def solve():

    N, M, Q = map(int, input().split())
    e = [list(map(int, input().split())) for i in range(Q)]

    def dfs(x, y):
        global list, res
        if x == N:
            tmp = 0
            for a, b, c, d in e:
                if list[b-1]-list[a-1] == c:
                    tmp += d
            res = max(res, tmp)
            return

        for i in range(y, M+1):
            w[x] = i
            dfs(x+1, i)

    dfs(0, 1)
    print(res)


if __name__ == "__main__":
    solve()


Fixed code:

lis = []
res = 0


def solve():

    N, M, Q = map(int, input().split())
    e = [list(map(int, input().split())) for i in range(Q)]
    global lis
    lis = [0]*N

    def dfs(x, y):
        global lis, res
        if x == N:
            tmp = 0
            for a, b, c, d in e:
                if lis[b-1]-lis[a-1] == c:
                    tmp += d
            res = max(res, tmp)
            return

        for i in range(y, M+1):
            lis[x] = i
            dfs(x+1, i)

    dfs(0, 1)
    print(res)


if __name__ == "__main__":
    solve()
Buggy code:
import itertools
n,m,q = map(int,input().split())
qset = [list(map(int, input().split())) for i in range(q)]

aa=list(itertools.combinations(range(1,m+1), r=n))

ans=0

for i in range(len(aa)):
  score = 0
  for n in range(len(qset)):
    a=aa[i]
    abcd=qset[n]
    if a[abcd[1]-1]-a[abcd[0]-1]==abcd[2]:
      score=score+abcd[3]
  if ans<score:
    ans=score
print(ans)

Fixed code:
import itertools
n,m,q = map(int,input().split())
qset = [list(map(int, input().split())) for i in range(q)]

aa=list(itertools.combinations_with_replacement(range(1,m+1), r=n))

ans=0

for i in range(len(aa)):
  score = 0
  for n in range(len(qset)):
    a=aa[i]
    abcd=qset[n]
    if a[abcd[1]-1]-a[abcd[0]-1]==abcd[2]:
      score=score+abcd[3]
  if ans<score:
    ans=score
print(ans)
Buggy code:
def ite(N, M):
    import itertools
    data = list(range(1, M+1, 1))
    return list(itertools.product(data, repeat=N))
  
def check(li):
    for i in range(len(li)-1):
        if li[i] > li[i+1]:
            return False
    return True
    
def score(l1, l2):
    s = 0
    for (a, b, c, d) in l2:
      if l1[b-1] - l1[a-1] == c:
            s += d
    return s
        

N, M, Q = list(map(int, input().split(" ")))
li = []
for i in range(Q):
    li.append(list(map(int, input().split(" "))))

m_s = 0
li2 = ite(N, M) 
for l2 in li2:
    if check(l2):
        s = score(l2, li)
        if m_s < s:
            m_s = s
            
print(m_s)

Fixed code:
def ite(N, M):
    import itertools
    return itertools.combinations_with_replacement(range(M),N)
def check(li):
    for i in range(len(li)-1):
        if li[i] > li[i+1]:
            return False
    return True
    
def score(l1, l2):
    s = 0
    for (a, b, c, d) in l2:
      if l1[b-1] - l1[a-1] == c:
            s += d
    return s
        

N, M, Q = list(map(int, input().split(" ")))
li = []
for i in range(Q):
    li.append(list(map(int, input().split(" "))))

m_s = 0
for l2 in ite(N, M):
    s = score(l2, li)
    if m_s < s:
      m_s = s
            
print(m_s)