#include<cstdio>
#include<algorithm>

int maxq = 55;

int n = 10, m, q, ans;
int A[15], a[55], b[55], c[55], d[55];

void DFS(int now)
{
	if(now == n + 1) {
		int res = 0;
		for(int i = 1; i <= q; ++i) {
			if(A[b[i]] - A[a[i]] == c[i])
				res += d[i];
		}
		ans = std::max(ans, res);
		return;
	}
	for(int j = A[now - 1]; j <= m; ++j) {
		A[now] = j;
		DFS(now + 1);
	}
}

int main() {
	scanf("%d%d%d", &n, &m, &q);
	for(int i = 1; i <= q; ++i)
		scanf("%d%d%d%d", &a[i], &b[i], &c[i], &d[i]);
	
	A[0] = 1, DFS(1);
	
	printf("%d", ans);
}