import itertools

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

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

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

A_s=itertools.combinations_with_replacement(nums,N)

ans=0

for A in A_s:

    tmp=0

    for i in range(Q):

        if A[a_b_c_d[i][1]-1]-A[a_b_c_d[i][0]-1]==a_b_c_d[i][2]:

            tmp+=a_b_c_d[i][3]

    if tmp>ans:

        ans=tmp

print(ans)
import sys

import itertools

import numpy as np

 

read = sys.stdin.buffer.read

readline = sys.stdin.buffer.readline

readlines = sys.stdin.buffer.readlines

 

N, M, Q = list(map(int, readline().split()))

 

A = np.array(list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)))

 

n = len(A)

score = np.zeros(n, np.int32)

m = list(map(int, read().split()))

for a, b, c, d in zip(m, m, m, m):

    cond = A[:, b - 1] - A[:, a - 1] == c

    score += d * cond

 

print((score.max()))
import itertools

N, M, Q = list(map(int, input().split()))
a_b_c_d = [list(map(int, input().split())) for _ in range(Q)]
nums = [i for i in range(1, M + 1)]
A_s = itertools.combinations_with_replacement(nums, N)
ans = 0
for A in A_s:
    tmp = 0
    for i in range(Q):
        if A[a_b_c_d[i][1] - 1] - A[a_b_c_d[i][0] - 1] == a_b_c_d[i][2]:
            tmp += a_b_c_d[i][3]
    if tmp > ans:
        ans = tmp
print(ans)

import sys
import itertools
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N, M, Q = list(map(int, readline().split()))
A = np.array(list(itertools.combinations_with_replacement(list(range(1, M + 1)), N)))
n = len(A)
score = np.zeros(n, np.int32)
m = list(map(int, read().split()))
for a, b, c, d in zip(m, m, m, m):
    cond = A[:, b - 1] - A[:, a - 1] == c
    score += d * cond
print((score.max()))

+import sys +import numpy as np -N, M, Q = list(map(int, input().split())) -a_b_c_d = [list(map(int, input().split())) for _ in range(Q)] -nums = [i for i in range(1, M + 1)] -A_s = itertools.combinations_with_replacement(nums, N) -ans = 0 -for A in A_s: -    tmp = 0 -    for i in range(Q): -        if A[a_b_c_d[i][1] - 1] - A[a_b_c_d[i][0] - 1] == a_b_c_d[i][2]: -            tmp += a_b_c_d[i][3] -    if tmp > ans: -        ans = tmp -print(ans) +read = sys.stdin.buffer.read +readline = sys.stdin.buffer.readline +readlines = sys.stdin.buffer.readlines +N, M, Q = list(map(int, readline().split())) +A = np.array(list(itertools.combinations_with_replacement(list(range(1, M + 1)), N))) +n = len(A) +score = np.zeros(n, np.int32) +m = list(map(int, read().split())) +for a, b, c, d in zip(m, m, m, m): +    cond = A[:, b - 1] - A[:, a - 1] == c +    score += d * cond +print((score.max()))