#標準入力

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

abcd = []

for _ in range(Q):

    tmp = list(map(int, input().split()))

    abcd.append(tmp)



#実装

import itertools as it

A_candidate = list(it.combinations_with_replacement(list(range(1, M + 1)), N))

ans = 0

for i in range(len(A_candidate)):

    tmp = 0

    for j in range(Q):

        if A_candidate[i][abcd[j][1] - 1] - A_candidate[i][abcd[j][0] - 1] == abcd[j][2] :

            tmp += abcd[j][3]

    if ans < tmp:

        ans = tmp

print(ans)

                   
#標準入力

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

abcd = []

for _ in range(Q):

    tmp = list(map(int, input().split()))

    abcd.append(tmp)



#実装

import itertools as it

A_candidate = list(it.combinations_with_replacement(list(range(1, M + 1)), N))

ans = 0

for i in range(len(A_candidate)):

    tmp = 0

    for j in range(Q):

        ABCD = abcd[j]

        if A_candidate[i][ABCD[1] - 1] - A_candidate[i][ABCD[0] - 1] == ABCD[2] :

            tmp += ABCD[3]

    if ans < tmp:

        ans = tmp

print(ans)

                   
# 標準入力
N, M, Q = list(map(int, input().split()))
abcd = []
for _ in range(Q):
    tmp = list(map(int, input().split()))
    abcd.append(tmp)
# 実装
import itertools as it

A_candidate = list(it.combinations_with_replacement(list(range(1, M + 1)), N))
ans = 0
for i in range(len(A_candidate)):
    tmp = 0
    for j in range(Q):
        if (
            A_candidate[i][abcd[j][1] - 1] - A_candidate[i][abcd[j][0] - 1]
            == abcd[j][2]
        ):
            tmp += abcd[j][3]
    if ans < tmp:
        ans = tmp
print(ans)

# 標準入力
N, M, Q = list(map(int, input().split()))
abcd = []
for _ in range(Q):
    tmp = list(map(int, input().split()))
    abcd.append(tmp)
# 実装
import itertools as it

A_candidate = list(it.combinations_with_replacement(list(range(1, M + 1)), N))
ans = 0
for i in range(len(A_candidate)):
    tmp = 0
    for j in range(Q):
        ABCD = abcd[j]
        if A_candidate[i][ABCD[1] - 1] - A_candidate[i][ABCD[0] - 1] == ABCD[2]:
            tmp += ABCD[3]
    if ans < tmp:
        ans = tmp
print(ans)

-        if ( -            A_candidate[i][abcd[j][1] - 1] - A_candidate[i][abcd[j][0] - 1] -            == abcd[j][2] -        ): -            tmp += abcd[j][3] +        ABCD = abcd[j] +        if A_candidate[i][ABCD[1] - 1] - A_candidate[i][ABCD[0] - 1] == ABCD[2]: +            tmp += ABCD[3]