#include <stdio.h>

int main()
{
	int i, N, M, Q, a[51], b[51], c[51], d[51];
	scanf("%d %d %d", &N, &M, &Q);
	for (i = 1; i <= Q; i++) scanf("%d %d %d %d", &(a[i]), &(b[i]), &(c[i]), &(d[i]));
	
	int A[12] = {}, max = 0, sum;
	for (i = 1, A[0] = 1, A[N+1] = M; i <= N; i++) A[i] = 1;
	while (1) {
		for (i = 1, sum = 0; i <= Q; i++) if (A[b[i]] - A[a[i]] == c[i]) sum += d[i];
		if (max < sum) max = sum;
		
		for (i = N; i >= 1; i--) if (A[i] < A[i+1]) break;
		if (i == 0) break;
		for (A[i++]++; i <= N; A[i++] = A[i-1]);
	}
	
	printf("%d\n", max);
	fflush(stdout);
	return 0;
}