# coding: utf-8

import sys



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, M, Q = lr()

ABCD = [lr() for _ in range(Q)]

A = [1] * N

ABCD.sort(key=lambda x: x[3], reverse=True)

ABCD.sort(key=lambda x: x[0])

answer = 0

for a in [1]:

    for b in range(a, M+1):

        for c in range(b, M+1):

            for d in range(c, M+1):

                for e in range(d, M+1):

                    for f in range(e, M+1):

                        for g in range(f, M+1):

                            for h in range(g, M+1):

                                for i in range(h, M+1):

                                    for j in range(i, M+1):

                                        temp = 0

                                        x = [a,b,c,d,e,f,g,h,i,j]

                                        for k, l, m, n in ABCD:

                                            if x[l-1] - x[k-1] == m:

                                                temp += n

                                        if temp > answer:

                                            answer = temp



print(answer)

# coding: utf-8

import sys

from itertools import combinations_with_replacement



sr = lambda: sys.stdin.readline().rstrip()

ir = lambda: int(sr())

lr = lambda: list(map(int, sr().split()))



N, M, Q = lr()

ABCD = [lr() for _ in range(Q)]

answer = 0

for x in combinations_with_replacement(list(range(1, M+1)), N):

    temp = 0

    for a, b, c, d in ABCD:

        if x[b-1] - x[a-1] == c:

            temp += d

    if temp > answer:

        answer = temp



print(answer)

#05
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M, Q = lr()
ABCD = [lr() for _ in range(Q)]
A = [1] * N
ABCD.sort(key=lambda x: x[3], reverse=True)
ABCD.sort(key=lambda x: x[0])
answer = 0
for a in [1]:
    for b in range(a, M + 1):
        for c in range(b, M + 1):
            for d in range(c, M + 1):
                for e in range(d, M + 1):
                    for f in range(e, M + 1):
                        for g in range(f, M + 1):
                            for h in range(g, M + 1):
                                for i in range(h, M + 1):
                                    for j in range(i, M + 1):
                                        temp = 0
                                        x = [a, b, c, d, e, f, g, h, i, j]
                                        for k, l, m, n in ABCD:
                                            if x[l - 1] - x[k - 1] == m:
                                                temp += n
                                        if temp > answer:
                                            answer = temp
print(answer)

# coding: utf-8
import sys
from itertools import combinations_with_replacement

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
N, M, Q = lr()
ABCD = [lr() for _ in range(Q)]
answer = 0
for x in combinations_with_replacement(list(range(1, M + 1)), N):
    temp = 0
    for a, b, c, d in ABCD:
        if x[b - 1] - x[a - 1] == c:
            temp += d
    if temp > answer:
        answer = temp
print(answer)
# 05

+from itertools import combinations_with_replacement -A = [1] * N -ABCD.sort(key=lambda x: x[3], reverse=True) -ABCD.sort(key=lambda x: x[0]) -for a in [1]: -    for b in range(a, M + 1): -        for c in range(b, M + 1): -            for d in range(c, M + 1): -                for e in range(d, M + 1): -                    for f in range(e, M + 1): -                        for g in range(f, M + 1): -                            for h in range(g, M + 1): -                                for i in range(h, M + 1): -                                    for j in range(i, M + 1): -                                        temp = 0 -                                        x = [a, b, c, d, e, f, g, h, i, j] -                                        for k, l, m, n in ABCD: -                                            if x[l - 1] - x[k - 1] == m: -                                                temp += n -                                        if temp > answer: -                                            answer = temp +for x in combinations_with_replacement(list(range(1, M + 1)), N): +    temp = 0 +    for a, b, c, d in ABCD: +        if x[b - 1] - x[a - 1] == c: +            temp += d +    if temp > answer: +        answer = temp +# 05