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

int retsu[10];
int ans = 0;
int n, m, q;
int a[55], b[55], c[55], d[55];
void dfs(int num, int last){
  //長さがnなら得点を数える
  // cout << "(" << num << "," << n << ")";
  if(num == n){
    int tmp = 0;
    for(int i=0;i<q;i++){
      if(retsu[b[i]-1]-retsu[a[i]-1]==c[i])tmp += d[i];
    }
    ans = max(ans, tmp);
    // cout << "[" << ans << "]";
    return;
  }
  for(int i=last;i<=m;i++){
    retsu[num]=i;
    dfs(num+1, i);
  }
}
int main(){
  cin >> n >> m >> q;
  
  for(int i=0;i<q;i++)cin >> a[i] >> b[i] >> c[i] >> d[i];
  
  dfs(0, 0);
  
  cout << ans << endl;
  return 0;
}
