qyliang/CodeNanoFix huggingface dataset:
Buggy code:
import sys
sys.setrecursionlimit(10**5)
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,B,C,D=map(int,input().split())
    a[i]=A;b[i]=B;c[i]=C;d[i]=D
r=[]
def dfs(i,depth,b,h):
    if depth==0:
        b.append(h)
        return
    for j in range(i,M):
        nh=h[:]
        nh.append(j)
        dfs(j,depth-1,b,nh)
dfs(1,10,r,[])
ans=0
for R in r:
    cnt=0
    for j in range(Q):
        if R[b[j]-1]-R[a[j]-1]==c[j]:
            cnt+=d[j]
    ans=max(cnt,ans)
print(ans)

Fixed code:
import sys
sys.setrecursionlimit(10**5)
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,B,C,D=map(int,input().split())
    a[i]=A;b[i]=B;c[i]=C;d[i]=D
r=[]
def dfs(i,depth,b,h):
    if depth==0:
        b.append(h)
        return
    for j in range(i,M+1):
        nh=h[:]
        nh.append(j)
        dfs(j,depth-1,b,nh)
dfs(1,10,r,[])
ans=0
for R in r:
    cnt=0
    for j in range(Q):
        if R[b[j]-1]-R[a[j]-1]==c[j]:
            cnt+=d[j]
    ans=max(cnt,ans)
print(ans)
Buggy code:
N, M, Q = [int(_) for _ in input().split()]
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q

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


def calc_score(A):
    acc = 0
    for i in range(Q):
        if c[i] == A[b[i]] - A[a[i]]:
            acc += d[i]
    return acc


max_score = -1


def dfs(A):
    if len(A) == N:
        global max_score
        max_score = max(calc_score(A), max_score)
    else:
        if len(A) == 0:
            A.append(1)
        else:
            A.append(A[-1])
        while (A[-1] <= M):
            dfs(A)
            A[-1] += 1


dfs([])
print(max_score)


Fixed code:
import copy

N, M, Q = [int(_) for _ in input().split()]
a = [0] * Q
b = [0] * Q
c = [0] * Q
d = [0] * Q

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


def calc_score(A):
    acc = 0
    for i in range(Q):
        if c[i] == A[b[i]] - A[a[i]]:
            acc += d[i]
    return acc


max_score = -1


def dfs(A):
    if len(A) == N:
        global max_score
        max_score = max(calc_score(A), max_score)
    else:
        if len(A) == 0:
            A.append(1)
        else:
            A.append(A[-1])
        while (A[-1] <= M):
            dfs(copy.deepcopy(A))
            A[-1] += 1


dfs([])
print(max_score)
Buggy code:
N, M, Q = list(map(int, input().split()))
A = []
B = []
C = []
D = []

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


ANS = []

import itertools
for i in itertools.product(range(1,M+1), repeat=N):
    f = 0
    for j in range(len(i)-1):
        if not i[j] < i[j+1]:
            f=1
    if f == 0:
        #print(i)
        ans = 0
        for q in range(Q):
            if i[B[q]-1] - i[A[q]-1] == C[q]:
                ans += D[q]
        ANS.append(ans)
print(max(ANS))


Fixed code:
N, M, Q = list(map(int, input().split()))
A = []
B = []
C = []
D = []

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

listA = list(range(1,N+1))
ANS = 0

import itertools
for i in itertools.combinations_with_replacement(range(1,M+1), N):
    f = 0
    for j in range(len(i)-1):
        if not i[j] <= i[j+1]:
            f=1
    if f == 0:
        #print(i)
        ans = 0
        for q in range(Q):
            if i[B[q]-1] - i[A[q]-1] == C[q]:
                ans += D[q]
        ANS = max([ANS, ans])
print(ANS)
#print(ANS)
Buggy code:
import itertools

N, M, Q = map(int, input().split())
x1 = [0]*Q
x2 = [0]*Q
x3 = [0]*Q
x4 = [0]*Q

for i in range(Q):
    x1[i], x2[i], x3[i], x4[i] = map(int, input().split())

score = 0
tmp = 0
lis = range(1, M+1)
A = []

for i in itertools.combinations(lis, N):
    A.append(list(i))

for i in range(len(A)):
    for j in range(Q):
        if(A[i][x2[j]-1] - A[i][x1[j]-1] == x3[j]): tmp += x4[j]
    if(tmp>score): score = tmp
    tmp = 0

print(score)


Fixed code:
import itertools

N, M, Q = map(int, input().split())
x1 = [0]*Q
x2 = [0]*Q
x3 = [0]*Q
x4 = [0]*Q

for i in range(Q):
    x1[i], x2[i], x3[i], x4[i] = map(int, input().split())
score = 0
tmp = 0
lis = range(1, M+1)
A = []

for i in itertools.combinations_with_replacement(lis, N):
    A.append(list(i))

for i in range(len(A)):
  for j in range(Q):
    if(A[i][x2[j]-1] - A[i][x1[j]-1] == x3[j]): tmp += x4[j]
  if(tmp>=score): score = tmp
  tmp = 0

print(score)
Buggy code:
#!/usr/bin/env python3

import itertools

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

ans = 0
cnt = 0
X = [i for i in range(1, M+1)]
Y = X * N

for i in itertools.permutations(Y, r=N):
    cnt = 0
    j = list(i)
    j.sort()
    for k in lis:
        if j[k[1]-1] - j[k[0]-1] == k[2]:
            cnt += k[3]
    ans = max(ans, cnt)

print(ans)

Fixed code:
#!/usr/bin/env python3

import itertools

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

ans = 0
cnt = 0
X = [i for i in range(1, M+1)]

for i in itertools.combinations_with_replacement(X, r=N):
    cnt = 0
    j = list(i)
    for k in lis:
        if j[k[1]-1] - j[k[0]-1] == k[2]:
            cnt += k[3]
    ans = max(ans, cnt)

print(ans)
Buggy code:
n,m,q=map(int,input().split())
a=[0]*q
b=[0]*q
c=[0]*q
d=[0]*q
A=[]
for i in range(q):
  a[i],b[i],c[i],d[i]=map(int,input().split())
def score(A):
  sum=0
  for (ai,bi,ci,di) in zip(a,b,c,d):
    if A[ai-1]-A[bi-1]==A[ci-1]:
      sum+=di
  return sum
def fbs(A):
  if len(A)==n:
    return score(A)
  res=0
  for v in range(1,m+1):
    A.append(v)
    res=max(res,fbs(A))
    A.pop()
  return res

print(fbs(A))

Fixed code:
n,m,q=map(int,input().split())
a=[0]*q
b=[0]*q
c=[0]*q
d=[0]*q
A=[]
for i in range(q):
  a[i],b[i],c[i],d[i]=map(int,input().split())
def score(A):
  sum=0
  for (ai,bi,ci,di) in zip(a,b,c,d):
    if A[bi-1]-A[ai-1]==ci:
      sum+=di
  return sum
def fbs(A):
  if len(A)==n:
    return score(A)
  if len(A)>0:
    pre_last=A[-1]
  else:
    pre_last=0
  res=0
  for v in range(pre_last,m):
    A.append(v)
    res=max(res,fbs(A))
    A.pop()
  return res

print(fbs(A))
Buggy code:

n, m , q = map(int, input().split())
 
l = []
for i in range(q):
  a,b,c,d = map(int, input().split())
  l.append((a,b,c,d))
max_score = 0
comb = [[1]]
while len(comb[0]) > 0:
  seed = comb.pop()
  if len(seed) == n:
    score = 0
    for j in l:
      if seed[j[1]-1]-seed[j[0]-1]==j[2]:
      
        score += j[3]
    if score > max_score:
      max_score = score
  else:
    for k in range(seed[-1], m+1):
      comb.append(seed.copy().append(k))
print(max_score)

Fixed code:
n, m , q = map(int, input().split())
 
l = []
for i in range(q):
  a,b,c,d = map(int, input().split())
  l.append((a,b,c,d))
max_score = 0
comb = [[1]]
while len(comb) > 0:
  seed = comb.pop()
  if len(seed) == n:
    score = 0
    for j in l:
      if seed[j[1]-1]-seed[j[0]-1]==j[2]:
      
        score += j[3]
    if score > max_score:
      max_score = score
  else:
    for k in range(seed[-1], m+1):
      s = seed[:]
      s.append(k)
      comb.append(s)
print(max_score)
Buggy code:
import itertools

n, m, q = [int(x) for x in input().split()]
 
tmp = []
for i in range(q):
    a, b, c, d = [int(x) for x in input().split()]
    tmp.append([a, b, c, d])

t = list(itertools.combinations_with_replacement(range(1, m + 1), m-1))

score = 0
for _t in t:
    _s = 0
    for a, b, c, d in tmp:
        if c == _t[b - 1] - _t[a - 1]:
            _s += d
    score = max(_s, score)
print(score)

Fixed code:
import itertools

n, m, q = [int(x) for x in input().split()]
 
tmp = []
for i in range(q):
    a, b, c, d = [int(x) for x in input().split()]
    tmp.append([a, b, c, d])

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

score = 0
for _t in t:
    _s = 0
    for a, b, c, d in tmp:
        if c == _t[b - 1] - _t[a - 1]:
            _s += d
    score = max(_s, score)
print(score)
Buggy code:
import itertools

nmq = list(map(int, input().split()))
n = nmq[0]
m = nmq[1]
q = nmq[2]
i = [list(map(int, input().split())) for i in range(q)]
a = list(range(1, m + 1))
a_all = list(itertools.combinations(a, n))
ans = 0
for x in a_all:
  val = 0
  for y in i:
    if x[y[1] - 1] - x[y[0] - 1] == y[2]:
      val += y[3]
  if val > ans:
    ans = val
print(ans)


Fixed code:
import itertools

nmq = list(map(int, input().split()))
n = nmq[0]
m = nmq[1]
q = nmq[2]
i = [list(map(int, input().split())) for i in range(q)]
a = list(range(1, m + 1))
a_all = list(itertools.combinations_with_replacement(a, n))
ans = 0
for x in a_all:
  val = 0
  for y in i:
    if x[y[1] - 1] - x[y[0] - 1] == y[2]:
      val = val + y[3]
  if val > ans:
    ans = val
print(ans)
Buggy code:
import itertools

N, M, Q = list(map(int,input().split()))
numbers = [i for i in range(1, M+1)]
array = itertools.combinations_wih_replacement(numbers, N)

input_data = [list(map(int,input().split())) for _ in range(Q)]

max_score = 0
for A in array:
    score = 0
    for _ in range(Q):
        a, b, c, d = input_data[_]
        a = a - 1
        b = b - 1
        if A[b] - A[a] == c:
            score += d
    if score > max_score:
        max_score = score
    
print(max_score)

Fixed code:
import itertools

N, M, Q = list(map(int,input().split()))
numbers = [i for i in range(1, M+1)]
array = itertools.combinations_with_replacement(numbers, N)

input_data = [list(map(int,input().split())) for _ in range(Q)]

max_score = 0
for A in array:
    score = 0
    for _ in range(Q):
        a, b, c, d = input_data[_]
        a = a - 1
        b = b - 1
        if A[b] - A[a] == c:
            score += d
    if score > max_score:
        max_score = score
    
print(max_score)
Buggy code:
n, m , q = map(int, input().split())
import itertools
n, m , q = map(int, input().split())

l = []
for i in range(q):
  a,b,c,d = map(int, input().split())
  l.append((a,b,c,d))
  
comb = itertools.combinations_with_replacement(range(1,m+1), n)

max_score = 0
for e in comb:
  score = 0
  for j in l:
    if e[j[1]-1]-e[j[0]-1]==j[2]:
      
      score += j[3]
  if score > max_score:
    max_score = score
print(max_score)

Fixed code:
import itertools
n, m , q = map(int, input().split())

l = []
for i in range(q):
  a,b,c,d = map(int, input().split())
  l.append((a,b,c,d))
  
comb = itertools.combinations_with_replacement(range(1,m+1), n)

max_score = 0
for e in comb:
  score = 0
  for j in l:
    if e[j[1]-1]-e[j[0]-1]==j[2]:
      
      score += j[3]
  if score > max_score:
    max_score = score
print(max_score)
Buggy code:
import numpy as np
import math
import scipy
import itertools

def score(arr):
    hoge = 0
    for ai,bi,ci,di in zip(a, b, c, d):
        if arr[bi-1]-arr[ai-1] == ci:
            hoge += di
    return hoge

def dfs(arr):
    if len(arr) == n:
        return score(arr)
    last = arr[-1] if len(arr) > 0 else 0
    res = 0
    for i in range(last, m+1):
        a.append(i)
        res = max(res, dfs(arr))
        a.pop()
    return res

def solve():
    global a, b, c, d, n, m, q
    n, m, q = map(int, input().split())
    a, b, c, d = [0]*q, [0]*q, [0]*q, [0]*q
    for i in range(q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
    print(dfs([]))
    return 0

if __name__ == "__main__":
    solve()


Fixed code:
import numpy as np
import math
import scipy
import itertools

def score(arr):
    hoge = 0
    for ai, bi, ci, di in zip(a, b, c, d):
        if arr[bi-1] - arr[ai-1] == ci:
            hoge += di
    return hoge

def dfs(arr):
    if len(arr) == n:
        return score(arr)
    res = 0
    prev_last = arr[-1] if len(arr) > 0 else 0
    for v in range(prev_last, m):
        arr.append(v)
        res = max(res, dfs(arr))
        arr.pop()
    return res

def solve():
    global a, b, c, d, n, m, q
    n, m, q = map(int, input().split())
    a, b, c, d = [0]*q, [0]*q, [0]*q, [0]*q
    for i in range(q):
        a[i], b[i], c[i], d[i] = map(int, input().split())
    print(dfs([]))
    return 0

if __name__ == "__main__":
    solve()
Buggy code:
import itertools
N,M,Q = map(int, input().split())
cand = list(itertools.combinations_with_replacement(N+M-1,N))
fs = [list(map(int, input().split())) for i in range(Q)]

def calc(fs,As):
  count = 0
  for a,b,c,d in fs:
    if As[b-1] - As[a-1] == a:
      count += d
	return count
ans = 0
for As in cand:
  ans = max(ans,calc(fs,As))

print(ans)

Fixed code:
from itertools import combinations_with_replacement as cw
N,M,Q = map(int, input().split())
cand = cw([i+1 for i in range(M)],N)
fs = [list(map(int, input().split())) for i in range(Q)]

def calc(fs,As):
  count = 0
  for a,b,c,d in fs:
    if As[b-1] - As[a-1] == c:
      count += d
  return count
ans = 0
for As in cand:
  ans = max(ans,calc(fs,As))

print(ans)
Buggy code:
import itertools
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]

list = []
for i in range(1, m+1):
    list.append(i)


wa = 0
ans = 0

for i in itertools.product(list, repeat=n):
    for a,b,c,d in abcd:
        # print(a,b,c,d)
        # if a <= len(i) and b <= len(i):
        if i[b-1]-i[a-1]==c:
            wa += d
            ans = max(ans, wa)
    wa = 0

print(ans)

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

list = []
for i in range(1, m+1):
    list.append(i)
 
 
wa = 0
ans = 0
 
for i in itertools.combinations_with_replacement(list, n):
    for a,b,c,d in abcd:
        # print(a,b,c,d)
        # if a <= len(i) and b <= len(i):
        if i[b-1]-i[a-1]==c:
            wa += d
            ans = max(ans, wa)
    wa = 0
 
print(ans)
Buggy code:
import itertools

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

for A_ in itertools.combinations([i for i in range(1, M+1)], N):
    A = list(A_)
    tmp_ans = 0
    for i in range(Q):
        if A[list_q[i][1]-1] - A[list_q[i][0]-1] == list_q[i][2]:
            tmp_ans += list_q[i][3]
    if ans < tmp_ans:
        ans = tmp_ans

print(ans)

Fixed code:
import itertools

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

for A_ in itertools.combinations_with_replacement([i for i in range(1, M+1)], N):
    A = list(A_)
    tmp_ans = 0
    for i in range(Q):
        if A[list_q[i][1]-1] - A[list_q[i][0]-1] == list_q[i][2]:
            tmp_ans += list_q[i][3]
    if ans < tmp_ans:
        ans = tmp_ans

print(ans)
Buggy code:
import itertools

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

m_li = []
for i in range(1,m+1):
    m_li.append(i)

li = []
mx = 0

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

for v in itertools.combinations(m_li,n):
    buf = 0
    for i in range(q):
        a = li[i][0]
        b = li[i][1]
        c = li[i][2]
        d = li[i][3]
        if v[b-1] - v[a-1] == c:
            buf += d
    if buf >= mx:
        mx = buf

print(mx)


Fixed code:
import itertools

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

m_li = []
for i in range(1,m+1):
    m_li.append(i)

li = []
mx = 0

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

for v in itertools.combinations_with_replacement(m_li,n):
    buf = 0
    for i in range(q):
        a = li[i][0]
        b = li[i][1]
        c = li[i][2]
        d = li[i][3]
        if v[b-1] - v[a-1] == c:
            buf += d
    if buf >= mx:
        mx = buf

print(mx)
Buggy code:
from itertools import combinations
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m,q=INTM()
    aq=[]
    for i in range(q):
        aq.append(LIST())
    number = [int(i+1) for i in range(m)]
    
    ans=0
    for i in combinations(number,n):
        temp=0
        for k in aq:
            if i[k[1]-1]-i[k[0]-1]==k[2]:
                temp+=k[3]
        ans=max(ans,temp)
    print(ans)
    
if __name__ == '__main__':
    do()

Fixed code:
from itertools import combinations_with_replacement
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m,q=INTM()
    aq=[]
    for i in range(q):
        aq.append(LIST())
    number = [int(i+1) for i in range(m)]
    
    ans=0
    for i in combinations_with_replacement(number,n):
        temp=0
        for k in aq:
            if i[k[1]-1]-i[k[0]-1]==k[2]:
                temp+=k[3]
        ans=max(ans,temp)
    print(ans)
    
if __name__ == '__main__':
    do()
Buggy code:
#import numpy as np
N,M,Q=map(int, input().split())
matrix=[]
for _ in range(Q):
    c=list(map(int, input().split()))
    matrix.append(c)
#matrix = np.array(matrix)
import itertools
ansscore = 0
combi = list(itertools.product(range(1,M+1), repeat=N))
for i in combi:
    i = list(i)
    i.sort()
    score=0
    for l in matrix:
        a=l[0]
        b=l[1]
        c=l[2]
        d=l[3]
        if i[b-1]-i[a-1]==c:
            score+=d
    ansscore = score if score>ansscore else ansscore

print(ansscore)

Fixed code:
#import numpy as np
N,M,Q=map(int, input().split())
matrix=[]
for _ in range(Q):
    c=list(map(int, input().split()))
    matrix.append(c)
#matrix = np.array(matrix)
import itertools
ansscore = 0
combi = list(itertools.combinations_with_replacement(range(1,M+1),N))
for i in combi:
    i = list(i)
    i.sort()
    score=0
    for l in matrix:
        a=l[0]
        b=l[1]
        c=l[2]
        d=l[3]
        if i[b-1]-i[a-1]==c:
            score+=d
    ansscore = score if score>ansscore else ansscore

print(ansscore)
Buggy code:
import sys
from itertools import combinations_with_replacement
from numba import njit


@njit('(i8,i8,i8[:,:])')
def solve(n, m, query):
    li = [i for i in range(1, m + 1)]
    max_point: int = 0
    for a in combinations_with_replacement(li, n):
        point = 0
        for qer in query:
            if a[qer[1] - 1] - a[qer[0] - 1] == qer[2]:
                point += qer[3]
        if point > max_point:
            max_point = point
    print(max_point)


def main():
    input = sys.stdin.buffer.readline
    n, m, q = map(int, input().split())
    query = [list(map(int, input().split())) for _ in range(q)]
    solve(n, m, query)


if __name__ == '__main__':
    main()


Fixed code:
import sys
from itertools import combinations_with_replacement


def main():
    input = sys.stdin.buffer.readline
    n, m, q = map(int, input().split())
    query = [list(map(int, input().split())) for _ in range(q)]
    li = [i for i in range(1, m + 1)]
    max_point = 0
    for a in combinations_with_replacement(li, n):
        point = 0
        for qer in query:
            if a[qer[1] - 1] - a[qer[0] - 1] == qer[2]:
                point += qer[3]
        if point > max_point:
            max_point = point
    print(max_point)


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


@njit('(i8,i8,i8[:,:])')
def solve(n, m, query):
    li = [0] * m
    for i in range(1, m + 1):
        li[i - 1] = i
    max_point: int = 0
    for a in combinations_with_replacement(li, n):
        point = 0
        for qer in query:
            if a[qer[1] - 1] - a[qer[0] - 1] == qer[2]:
                point += qer[3]
        if point > max_point:
            max_point = point
    print(max_point)


def main():
    input = sys.stdin.buffer.readline
    n, m, q = map(int, input().split())
    query = [list(map(int, input().split())) for _ in range(q)]
    solve(n, m, query)


if __name__ == '__main__':
    main()


Fixed code:
import sys
from itertools import combinations_with_replacement


def main():
    input = sys.stdin.buffer.readline
    n, m, q = map(int, input().split())
    query = [list(map(int, input().split())) for _ in range(q)]
    li = [0] * m
    for i in range(1, m + 1):
        li[i - 1] = i
    max_point = 0
    for a in combinations_with_replacement(li, n):
        point = 0
        for qer in query:
            if a[qer[1] - 1] - a[qer[0] - 1] == qer[2]:
                point += qer[3]
        if point > max_point:
            max_point = point
    print(max_point)


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

nums = [i for i in range(1, 10)]
ans = 0
for nums in itertools.combinations_with_replacement(nums, r=n):
	tmp = 0
	for query in queries:
		if nums[query[1] - 1] - nums[query[0] - 1] == query[2]:
			tmp += query[3]
	ans = max(ans, tmp)
print(ans)

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

nums = [i for i in range(1, m + 1)]
ans = 0
for nums in itertools.combinations_with_replacement(nums, r=n):
	tmp = 0
	for query in queries:
		if nums[query[1] - 1] - nums[query[0] - 1] == query[2]:
			tmp += query[3]
	ans = max(ans, tmp)
print(ans)
Buggy code:
n, m, q = map(int, input().split())
a_list = []
b_list = []
c_list = []
d_list = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
    c_list.append(c)
    d_list.append(d)

import itertools

ans = 0
h_list = [i+1 for i in range(m)]
for A in itertools.combinations(h_list, n):
    max_d = 0
    for a, b, c, d in zip(a_list, b_list, c_list, d_list):
        if A[b-1]-A[a-1] == c:
            max_d += d
    ans = max(ans, max_d)

print(ans)

Fixed code:
n, m, q = map(int, input().split())
a_list = []
b_list = []
c_list = []
d_list = []
for _ in range(q):
    a, b, c, d = map(int, input().split())
    a_list.append(a)
    b_list.append(b)
    c_list.append(c)
    d_list.append(d)

import itertools

ans = 0
h_list = [i+1 for i in range(m)]
for A in itertools.combinations_with_replacement(h_list, n):
    # print(A)
    max_d = 0
    for a, b, c, d in zip(a_list, b_list, c_list, d_list):
        if A[b-1]-A[a-1] == c:
            max_d += d
    ans = max(ans, max_d)

print(ans)
Buggy code:
from itertools import combinations_with_replacement as comb

n,m,q = map(int, input().split(' '))
lis = [list(map(int, input().split())) for _ in range(q)]
tes = comb(range(1,m))
res = 0
for i in tes:
    te = 0
    for a,b,c,d in lis:
        if c == i[b-1] - i[a-1]:
            te += d
    res = max(te,res)
print(res)

Fixed code:
from itertools import combinations_with_replacement as comb

n,m,q = map(int, input().split(' '))
lis = [list(map(int, input().split())) for _ in range(q)]
tes = comb(range(1,m+1),n)
res = 0
for i in tes:
    te = 0
    for a,b,c,d in lis:
        if c == i[b-1] - i[a-1]:
            te += d
    res = max(te,res)
print(res)