# -*- coding: utf-8 -*-



def input_one_number():

    return int(eval(input()))



def input_multiple_number():

    return list(map(int, input().split()))



def input_multiple_number_as_list():

    return list(map(int, input().split()))





N,M,Q = input_multiple_number()



lists = []



for i in range(Q):

	lis = input_multiple_number_as_list()

	lists.append(lis)



ans = 0

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

	for i2 in range(i,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):

										score = 0

										for _q in lists:

											a = [i,i2,i3,i4,i5,i6,i7,i8,i9,i10]

											if (a[_q[1]-1]-a[_q[0]-1]) == _q[2]:

												score += _q[3]

										ans = max(ans,score)

										

print(ans)









# -*- coding: utf-8 -*-



def input_one_number():

    return int(eval(input()))



def input_multiple_number():

    return list(map(int, input().split()))



def input_multiple_number_as_list():

    return list(map(int, input().split()))





N,M,Q = input_multiple_number()



lists = []



for i in range(Q):

	lis = input_multiple_number_as_list()

	lists.append(lis)



ans = 0

import itertools

for a in itertools.combinations_with_replacement(list(range(1,M+1)),N):

	score = 0

	for _q in lists:

		#a = [i,i2,i3,i4,i5,i6,i7,i8,i9,i10]

		if (a[_q[1]-1]-a[_q[0]-1]) == _q[2]:

			score += _q[3]

	ans = max(ans,score)

										

print(ans)









# -*- coding: utf-8 -*-
def input_one_number():
    return int(eval(input()))


def input_multiple_number():
    return list(map(int, input().split()))


def input_multiple_number_as_list():
    return list(map(int, input().split()))


N, M, Q = input_multiple_number()
lists = []
for i in range(Q):
    lis = input_multiple_number_as_list()
    lists.append(lis)
ans = 0
for i in range(1, M + 1):
    for i2 in range(i, 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):
                                        score = 0
                                        for _q in lists:
                                            a = [i, i2, i3, i4, i5, i6, i7, i8, i9, i10]
                                            if (a[_q[1] - 1] - a[_q[0] - 1]) == _q[2]:
                                                score += _q[3]
                                        ans = max(ans, score)
print(ans)

# -*- coding: utf-8 -*-
def input_one_number():
    return int(eval(input()))


def input_multiple_number():
    return list(map(int, input().split()))


def input_multiple_number_as_list():
    return list(map(int, input().split()))


N, M, Q = input_multiple_number()
lists = []
for i in range(Q):
    lis = input_multiple_number_as_list()
    lists.append(lis)
ans = 0
import itertools

for a in itertools.combinations_with_replacement(list(range(1, M + 1)), N):
    score = 0
    for _q in lists:
        # a = [i,i2,i3,i4,i5,i6,i7,i8,i9,i10]
        if (a[_q[1] - 1] - a[_q[0] - 1]) == _q[2]:
            score += _q[3]
    ans = max(ans, score)
print(ans)

-for i in range(1, M + 1): -    for i2 in range(i, 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): -                                        score = 0 -                                        for _q in lists: -                                            a = [i, i2, i3, i4, i5, i6, i7, i8, i9, i10] -                                            if (a[_q[1] - 1] - a[_q[0] - 1]) == _q[2]: -                                                score += _q[3] -                                        ans = max(ans, score) +import itertools + +for a in itertools.combinations_with_replacement(list(range(1, M + 1)), N): +    score = 0 +    for _q in lists: +        # a = [i,i2,i3,i4,i5,i6,i7,i8,i9,i10] +        if (a[_q[1] - 1] - a[_q[0] - 1]) == _q[2]: +            score += _q[3] +    ans = max(ans, score)