#include<bits/stdc++.h>
using namespace std;

int N,M,Q;
int a[55],b[55],c[55],d[55];
int tmp[20];

int solve(int i){
    int ans=0;
    if(i==(N+1)){
        for(int j=0;j<Q;j++){
            if(tmp[b[j]]-tmp[a[j]]==c[j]){
                ans+=d[j];
            }
        }
        return ans;
    }
    for(int v=tmp[i-1];v<=M;v++){
        tmp[i]=v;
        ans=max(ans,solve(i+1));
    }
    return ans;
}

int main(){
    cin >> N >> M >> Q;
    for(int i=0;i<Q;i++){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    tmp[0]=1;
    cout << solve(1) << endl;
}