#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int n,m,q;
int a[50],b[50],c[50],d[50];
int process();
int process_sub(int ps);
int ch();
int A[13];

int main()
{
    scanf("%d %d %d",&n,&m,&q);

    int i;

    for(i=0;i<q;i++)
        scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);

    int max = process();
    printf("%d\n",max);

    return 0;
}

int process()
{
    int i;
    int ps = 0;
    int max=0,ans;

    for(i=1;i<=m;i++)
    {
        A[0] = i;
       ans =  process_sub(ps+1);
        if(max < ans)
            max = ans;
    }

    return max;
}

int process_sub(int ps)
{
    int max=0,ans;
    if(ps == n)
    {
        ans = ch();
        return ans;
    }

    int i;

    for(i = A[ps-1]; i<=m;i++)
    {
        A[ps] = i;
        ans = process_sub(ps+1);
        if(max < ans)
            max = ans;
    }

    return max;
}

int ch()
{
    int i;

    int sum_d = 0;

    for(i=0;i<q;i++)
    {
        if(A[b[i]-1] - A[a[i]-1] == c[i])
            sum_d += d[i];
    }

    

    return sum_d;
}