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

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

ans=0

for i1 in range(1,m+1): #愚直に10重ループを行っても、そのループ回数は高々92378回

  for i2 in range(i1,m+1):

    for i3 in range(i2,m+1):

      for i4 in range(i3,m+1):

        for i5 in range(i4,m+1):

          for i6 in range(i5,m+1):

            for i7 in range(i6,m+1):

              for i8 in range(i7,m+1):

                for i9 in range(i8,m+1):

                  for i10 in range(i9,m+1):

                    tmp=0

                    arrs=[0,i1,i2,i3,i4,i5,i6,i7,i8,i9,i10]

                    for a,b,c,d in arr: #条件を満たす数列について、最大値を求める

                      if arrs[b]-arrs[a]==c:

                        tmp+=d

                    ans=max(ans,tmp)

print(ans)
# 入力

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

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()))

    a[i] -= 1

    b[i] -= 1



# スコア計算

def score(A):

    tmp = 0

    for ai, bi, ci, di in zip(a, b, c, d):

        if A[bi] - A[ai] == ci:

            tmp += di

    return tmp



# DFS

def dfs(A):

    if len(A) == N:

        return score(A) # 数列 A のスコアを返す

    res = 0

    prev_last = A[-1] if len(A) > 0 else 0

    for v in range(prev_last, M):

        A.append(v)

        res = max(res, dfs(A)) # 再帰呼出しながら、スコア最大値も更新

        A.pop()

    return res



# 求める

print((dfs([])))
n, m, q = list(map(int, input().split()))
arr = [list(map(int, input().split())) for _ in range(q)]
ans = 0
for i1 in range(1, m + 1):  # 愚直に10重ループを行っても、そのループ回数は高々92378回
    for i2 in range(i1, m + 1):
        for i3 in range(i2, m + 1):
            for i4 in range(i3, m + 1):
                for i5 in range(i4, m + 1):
                    for i6 in range(i5, m + 1):
                        for i7 in range(i6, m + 1):
                            for i8 in range(i7, m + 1):
                                for i9 in range(i8, m + 1):
                                    for i10 in range(i9, m + 1):
                                        tmp = 0
                                        arrs = [
                                            0,
                                            i1,
                                            i2,
                                            i3,
                                            i4,
                                            i5,
                                            i6,
                                            i7,
                                            i8,
                                            i9,
                                            i10,
                                        ]
                                        for a, b, c, d in arr:  # 条件を満たす数列について、最大値を求める
                                            if arrs[b] - arrs[a] == c:
                                                tmp += d
                                        ans = max(ans, tmp)
print(ans)

# 入力
N, M, Q = list(map(int, input().split()))
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()))
    a[i] -= 1
    b[i] -= 1
# スコア計算
def score(A):
    tmp = 0
    for ai, bi, ci, di in zip(a, b, c, d):
        if A[bi] - A[ai] == ci:
            tmp += di
    return tmp


# DFS
def dfs(A):
    if len(A) == N:
        return score(A)  # 数列 A のスコアを返す
    res = 0
    prev_last = A[-1] if len(A) > 0 else 0
    for v in range(prev_last, M):
        A.append(v)
        res = max(res, dfs(A))  # 再帰呼出しながら、スコア最大値も更新
        A.pop()
    return res


# 求める
print((dfs([])))

-n, m, q = list(map(int, input().split())) -arr = [list(map(int, input().split())) for _ in range(q)] -ans = 0 -for i1 in range(1, m + 1):  # 愚直に10重ループを行っても、そのループ回数は高々92378回 -    for i2 in range(i1, m + 1): -        for i3 in range(i2, m + 1): -            for i4 in range(i3, m + 1): -                for i5 in range(i4, m + 1): -                    for i6 in range(i5, m + 1): -                        for i7 in range(i6, m + 1): -                            for i8 in range(i7, m + 1): -                                for i9 in range(i8, m + 1): -                                    for i10 in range(i9, m + 1): -                                        tmp = 0 -                                        arrs = [ -                                            0, -                                            i1, -                                            i2, -                                            i3, -                                            i4, -                                            i5, -                                            i6, -                                            i7, -                                            i8, -                                            i9, -                                            i10, -                                        ] -                                        for a, b, c, d in arr:  # 条件を満たす数列について、最大値を求める -                                            if arrs[b] - arrs[a] == c: -                                                tmp += d -                                        ans = max(ans, tmp) -print(ans) +# 入力 +N, M, Q = list(map(int, input().split())) +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())) +    a[i] -= 1 +    b[i] -= 1 +# スコア計算 +def score(A): +    tmp = 0 +    for ai, bi, ci, di in zip(a, b, c, d): +        if A[bi] - A[ai] == ci: +            tmp += di +    return tmp + + +# DFS +def dfs(A): +    if len(A) == N: +        return score(A)  # 数列 A のスコアを返す +    res = 0 +    prev_last = A[-1] if len(A) > 0 else 0 +    for v in range(prev_last, M): +        A.append(v) +        res = max(res, dfs(A))  # 再帰呼出しながら、スコア最大値も更新 +        A.pop() +    return res + + +# 求める +print((dfs([])))