import sys,itertools

input = sys.stdin.readline



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

seq = list(range(n+m-1))

p = list(itertools.combinations(seq,n))



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] = list(map(int,input().split()))



res = 0

for i in range(len(p)):

    t = [0]*n

    pp = sorted(p[i])

    idx = 0

    for e in pp:

        t[idx] = 1+e-idx

        idx += 1

    

    tmp = 0

    for j in range(q):

        if t[b[j]-1] - t[a[j]-1] == c[j]:

            tmp += d[j]

    

    res = max(res,tmp)



print(res)

import itertools



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

seq = list(range(n+m-1))

p = list(itertools.combinations(seq, n))



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] = list(map(int,input().split()))



res = 0

for i in range(len(p)):

    t = [0] * n

    pp = sorted(p[i])

    idx = 0

    for e in pp:

        t[idx] = 1 + e - idx

        idx += 1

    

    tmp = 0

    for j in range(q):

        if t[b[j]-1] - t[a[j]-1] == c[j]:

            tmp += d[j]

    

    res = max(res, tmp)



print(res)
import sys, itertools

input = sys.stdin.readline
n, m, q = list(map(int, input().split()))
seq = list(range(n + m - 1))
p = list(itertools.combinations(seq, n))
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] = list(map(int, input().split()))
res = 0
for i in range(len(p)):
    t = [0] * n
    pp = sorted(p[i])
    idx = 0
    for e in pp:
        t[idx] = 1 + e - idx
        idx += 1
    tmp = 0
    for j in range(q):
        if t[b[j] - 1] - t[a[j] - 1] == c[j]:
            tmp += d[j]
    res = max(res, tmp)
print(res)

import itertools

n, m, q = list(map(int, input().split()))
seq = list(range(n + m - 1))
p = list(itertools.combinations(seq, n))
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] = list(map(int, input().split()))
res = 0
for i in range(len(p)):
    t = [0] * n
    pp = sorted(p[i])
    idx = 0
    for e in pp:
        t[idx] = 1 + e - idx
        idx += 1
    tmp = 0
    for j in range(q):
        if t[b[j] - 1] - t[a[j] - 1] == c[j]:
            tmp += d[j]
    res = max(res, tmp)
print(res)

-import sys, itertools +import itertools -input = sys.stdin.readline