#include <stdio.h>

int main(void){
  
  int n , m , Q;
  scanf("%d %d %d",&n,&m,&Q);
  
  int a[Q],b[Q],c[Q],d[Q];
  for(int i = 0;i < Q;i ++){
    scanf("%d %d %d %d",&a[i],&b[i],&c[i],&d[i]);
  }
 
  int A[11] , max = 0 ,count = 0;
  
  for(int i = 1;i <=m&&1<=n;i ++){
   A[1] = i;
    for(int j = i+1;j <=m&&2<=n;j ++){
       A[2] = j;
       for(int k = j+1;k <=m&&3<=n;k++){
         A[3] = k;
        for(int l = k+1;l <=m&&4<=n;l++){
          A[4] = l;
          for(int o = l+1;o <=m&&5<=n;o++){
            A[5] = o;
            for(int q= o+1;q<=m&&6<=n;q++){
              A[6] = q;
              for(int r = q+1;r<=m&&7<=n;r++){
                A[7] = r;
                for(int s = r+1;s<=m&&8<=n;s++){
                  A[8] = s;
                  for(int t =s+1;t <=m&&9<=n;t++){
                    A[9] = t;
                    for(int u =t+1;u<=m&&n==10;u++){
                      A[10] = u;
                      
                      printf("%d %d %d\n",A[1],A[2],A[3]);
                      for(int v = 0;v < Q;v ++){
                        if(A[b[v]] - A[a[v]] == c[v]){
                          count += d[v];
                          printf("%d\n",count);
                        }
                      }
                        if(max<count){
                          max = count;
                        }
                        count = 0;
                     }}}}}}}}}}
  printf("%d",max);
  
  return 0;
}
