#include<stdio.h>
enum{
  a,
  b,
  c,
  d,
};

int calcscore(int A[],int abcd[][4], int Q){
  int score=0;
  for(int i=0;i<Q;i++){
    if(A[abcd[i][b]]-A[abcd[i][a]]==abcd[i][c]) score += abcd[i][d];
  }
  return score;
}

int makeA(int array[], int N, int M, int x, int a){
  int highscore,temp;
  for(int i=a;i<M;i++){
    array[x]=i;
  }
}
    

int main(){
  int N,M,Q,abcd[60][4];
  scanf("%d %d %d",&N,&M,&Q);
  for(int i=0;i<Q;i++){
    scanf("%d %d %d %d",&abcd[i][a],&abcd[i][b],&abcd[i][c],&abcd[i][d]);
  }
  
  int A[N],highscore=0,temp;
  for(int i=0;i<N;i++){A[i]=1;}
  
  for(int i=N;i>0;i--){
  	for(int j=A[i-1];j<=M;j++){
      A[i]=j;
      temp = calcscore(A,abcd,Q);
      if(highscore < temp){highscore=temp;}
    }
  }
  printf("%d",highscore);
}