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

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

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length

for i in range(q):
    num = list(map(int,input().split()))
    for j in range(length):
        if int(a[j][num[1]-1])-int(a[j][num[0]-1]) == int(num[2]):
            memo[j] += num[3]
print(max(memo))



Fixed submission:
import itertools

n,m,q = map(int,input().split())
num = [list(map(int,input().split())) for i in range(q)]

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length
ans = 0

for i in range(length):#組み合わせの数回す
    sum = 0
    for j in range(q):
       if a[i][num[j][1]-1] - a[i][num[j][0]-1]  == num[j][2]:
            sum += num[j][3]
    ans = max(sum,ans)
print(ans)

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

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

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length

for i in range(q):
    num = list(map(int,input().split()))
    for j in range(length):
        if int(a[j][num[1]-1])-int(a[j][num[0]-1]) == int(num[2]):
            memo[j] += num[3]
print(max(memo))



Fixed submission:
import itertools

n,m,q = map(int,input().split())
num = [list(map(int,input().split())) for i in range(q)]

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length
ans = 0

for i in range(length):#組み合わせの数回す
    sum = 0
    for j in range(q):
       if a[i][num[j][1]-1] - a[i][num[j][0]-1]  == num[j][2]:
            sum += num[j][3]
    ans = max(sum,ans)
print(ans)

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

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

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length

for i in range(q):
    num = list(map(int,input().split()))
    for j in range(length):
        if int(a[j][num[1]-1])-int(a[j][num[0]-1]) == int(num[2]):
            memo[j] += num[3]
print(max(memo))



Fixed submission:
import itertools

n,m,q = map(int,input().split())
num = [list(map(int,input().split())) for i in range(q)]

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length
ans = 0

for i in range(length):#組み合わせの数回す
    sum = 0
    for j in range(q):
       if a[i][num[j][1]-1] - a[i][num[j][0]-1]  == num[j][2]:
            sum += num[j][3]
    ans = max(sum,ans)
print(ans)

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

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

memo = []
number = []
for i in range(m):
    number.append(i+1)
len = m

for j in range(math.factorial(n+m-1)//(math.factorial(n)*math.factorial(m-1))):
    memo.append(0)

a = list(itertools.combinations_with_replacement(number,n))
for i in range(q):
    num = list(map(int,input().split()))
    for j in range(math.factorial(n+m-1)//(math.factorial(n)*math.factorial(m-1))):
        if int(a[j][num[1]-1])-int(a[j][num[0]-1]) == int(num[2]):
            memo[j] += num[3]
print(max(memo))



Fixed submission:
import itertools

n,m,q = map(int,input().split())
num = [list(map(int,input().split())) for i in range(q)]

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length
ans = 0

for i in range(length):#組み合わせの数回す
    sum = 0
    for j in range(q):
       if a[i][num[j][1]-1] - a[i][num[j][0]-1]  == num[j][2]:
            sum += num[j][3]
    ans = max(sum,ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools

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

total = 0

memo = []
number = []
for i in range(m):
    number.append(i+1)
len = m

for j in range((m+3-1)*(m+2-1)*(m)//6):
    memo.append(0)


a = list(itertools.combinations_with_replacement(number,n))
for i in range(q):
    num = list(map(int,input().split()))
    for j in range((m+3-1)*(m+2-1)*(m)//6):
        if int(a[j][num[1]-1])-int(a[j][num[0]-1]) == int(num[2]):
            memo[j] += num[3]
print(max(memo))



Fixed submission:
import itertools

n,m,q = map(int,input().split())
num = [list(map(int,input().split())) for i in range(q)]

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length
ans = 0

for i in range(length):#組み合わせの数回す
    sum = 0
    for j in range(q):
       if a[i][num[j][1]-1] - a[i][num[j][0]-1]  == num[j][2]:
            sum += num[j][3]
    ans = max(sum,ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools

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

total = 0

memo = []
number = []
for i in range(m):
    number.append(i+1)
len = len(number)

for j in range((len+3-1)*(len+2-1)*(len)//6):
    memo.append(0)

a = list(itertools.combinations_with_replacement(number,n))
for i in range(q):
    num = list(map(int,input().split()))
    for j in range((len+3-1)*(len+2-1)*(len)//6):
        if int(a[j][num[1]-1])-int(a[j][num[0]-1]) == num[2]:
            memo[j] += num[3]
print(max(memo))



Fixed submission:
import itertools

n,m,q = map(int,input().split())
num = [list(map(int,input().split())) for i in range(q)]

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length
ans = 0

for i in range(length):#組み合わせの数回す
    sum = 0
    for j in range(q):
       if a[i][num[j][1]-1] - a[i][num[j][0]-1]  == num[j][2]:
            sum += num[j][3]
    ans = max(sum,ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools

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

total = 0

memo = []
number = []
for i in range(m):
    number.append(i+1)
len = len(number)

for j in range((len+3-1)*(len+2-1)*(len)//6):
    memo.append(0)

a = list(itertools.combinations_with_replacement(number,n))
for i in range(q):
    num = list(map(int,input().split()))
    for j in range((len+3-1)*(len+2-1)*(len)//6):
        if int(a[j][num[1]-1])-int(a[j][num[0]-1]) == num[2]:
            memo[j] += num[3]


print(max(memo))



Fixed submission:
import itertools

n,m,q = map(int,input().split())
num = [list(map(int,input().split())) for i in range(q)]

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length
ans = 0

for i in range(length):#組み合わせの数回す
    sum = 0
    for j in range(q):
       if a[i][num[j][1]-1] - a[i][num[j][0]-1]  == num[j][2]:
            sum += num[j][3]
    ans = max(sum,ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
import itertools

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

total = 0

memo = []
number = []
for i in range(m):
    number.append(i+1)
len = len(number)

for j in range((len+3-1)*(len+2-1)*(len)//6):
    memo.append(0)


for i in range(q):
    num = list(map(int,input().split()))
    for j in range((len+3-1)*(len+2-1)*(len)//6):
        a = list(itertools.combinations_with_replacement(number,n))
        if int(a[j][num[1]-1])-int(a[j][num[0]-1]) == num[2]:
            memo[j] += num[3]


print(max(memo))



Fixed submission:
import itertools

n,m,q = map(int,input().split())
num = [list(map(int,input().split())) for i in range(q)]

number = []
for i in range(m):
    number.append(i+1)
a = list(itertools.combinations_with_replacement(number,n))
length = len(a)
memo = [0] * length
ans = 0

for i in range(length):#組み合わせの数回す
    sum = 0
    for j in range(q):
       if a[i][num[j][1]-1] - a[i][num[j][0]-1]  == num[j][2]:
            sum += num[j][3]
    ans = max(sum,ans)
print(ans)