import std;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] lreads(T = long)(long n){return generate(()=>readln.chomp.to!T()).take(n).array();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue(T, alias less = "a<b") = BinaryHeap!(Array!T, less);
// dfmt on

void main()
{
    long N, M, Q;
    scan(N, M, Q);
    auto a = new long[](Q);
    auto b = new long[](Q);
    auto c = new long[](Q);
    auto d = new long[](Q);
    foreach (i; 0 .. Q)
        scan(a[i], b[i], c[i], d[i]);
    a[] -= 1;
    b[] -= 1;

    long dfs1(long[] A)
    {
        if (A.length == N)
        {
            // writeln(A);
            long ret;
            foreach (i; 0 .. Q)
            {
                if (A[b[i]] - A[a[i]] == c[i])
                    ret += d[i];
            }
            return ret;
        }
        long m = A.length == 0 ? 1 : A[$ - 1];
        long ret = long.min;
        foreach (x; m .. M + 1)
        {
            ret = ret.max(dfs1(A ~ x));
        }
        return ret;
    }

    writeln(dfs1([]));
}
