#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define MAX(a,b) a=a>b?a:b
#define MIN(a,b) a=a<b?a:b
#define REP(i,x,n) for(int i=x;i<n;i++)
#define REPR(i,x,n) for(int i=n-1;i>=x;i--)
#define pb  push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLr(obj) (obj).rbegin(), (obj).rend()
#define endl "\n"
#define F first
#define S second
#define EN cout<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
 ll dp[2000][2000];

ll n ,m,q,z[1010]={};
ll a[101],b[101],c[101],d[101];

ll co(ll cn,ll sum,vector<ll>v){

    if(v.size()>=n){
        ll ans=0;
        rep(j,q){
            if(v[b[j]-1]-v[a[j]-1]==c[j]){
                ans+=d[j];
            }
        }
        return ans;
    }
    REP(i,cn,m+1){
        ll sum2=sum;
        vector<ll> v2=v;
        v2.pb(i);
        
        sum=max(sum,co(i,sum2,v2));
    }
    return sum;
}

int main(){
   
   string s ;
   cin>>n>>m>>q;

   rep(i,q){
       cin>>a[i]>>b[i]>>c[i]>>d[i];
   }
   cout<<co(1,0,{})<<endl;;

}
