#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int N, M, Q,Ans=0;
vector<int> A(50), B(50), C(50), D(50), V(10);
void dfs(int E, int F){
  if(E==N){
    int Sum=0;
    rep(i, Q)if (V.at(B.at(i))-V.at(A.at(i))==C.at(i)) Sum+=D.at(i);
    Ans=max(Ans, Sum);
    return;
  }
  for(int i=F; i<=M; i++){
    V.at(E)=i;
    dfs(E+1,i);
  }
}
int main(){
  cin >> N >> M >> Q;
  rep(i,Q){
    cin >> A.at(i) >> B.at(i) >> C.at(i) >> D.at(i);
    A.at(i)--;
    B.at(i)--;
  }
  dfs(0,1);
  cout << Ans << endl;
}