#include <stdio.h>
#include <stdlib.h>
int n, m, q;
int a[55], b[55], c[55], d[55];
int A[10] = {};
int dfs(int *A, int j)
{
    if (j == n)
    {
        int ans = 0;
        for (int i = 0; i < q; i++)
        {
            if (A[b[i]] - A[a[i]] == c[i])
            {
                ans += d[i];
            }
        }
        return ans;
    }
    int max = 0;
    for (int i = A[j - 1]; i <= m; i++)
    {
        A[j] = i;
        int t = dfs(A, j + 1);
        max = (max > t) ? max : t;
    }
    return max;
}
int main()
{
    scanf("%d %d %d", &n, &m, &q);
    for (int i = 0; i < q; i++)
    {
        scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
        a[i]--;
        b[i]--;
    }
    A[0] = 1;
    printf("%ld", dfs(A, 1));
    return 0;
}