#include <stdio.h>

#define N 16

int buffer[N];
int allcombi[300][11];
int index=0;

void print_combination(int n)
{
  for (int i = 1; i <= n; i++){
      allcombi[index][i] = buffer[i-1];
  }
  
  for(int i = 1 ; i <= n; i++){
      for(int j = n; j > i; j--){
          if(allcombi[index][j] < allcombi[index][j-1]){
              int tmp = allcombi[index][j];
              allcombi[index][j] = allcombi[index][j-1];
              allcombi[index][j-1] = tmp;
          }
      }
  }
  /*
  for(int i = 1; i <= n; i++){
      printf("%d ", allcombi[index][i]);
  }*/
  index++;
  //printf("\n");
}

void comb_sub(int n, int r, int m)
{
  if (r == 0)
    print_combination(m);
  else if (n == r) {
    for (int i = r; i > 0; i--)
      buffer[m++] = i;
    print_combination(m);
  } else {
    comb_sub(n - 1, r, m);
    buffer[m] = n;
    comb_sub(n - 1, r - 1, m + 1);
  }
}

void combinations(int n, int r)
{
  if (r > 0 && r <= N) comb_sub(n, r, 0);
}

int main(void){
    int N_,M,Q;
    int ans = 0;
    int Q4[50][4];
    
    scanf("%d%d%d",&N_,&M,&Q);
    combinations(M,N_);
    
    for(int i = 0; i < Q; i++){
        scanf("%d%d%d%d",&Q4[i][0],&Q4[i][1],&Q4[i][2],&Q4[i][3]);
    }
    for(int j = 0; j < index; j++){
        int tmp = 0;
        for(int i = 0; i < Q; i++){
            //printf("(j,Q)=(%d,%d)  --  (%d) =? (%d)\n",j,i,(allcombi[j][Q4[i][1]]-allcombi[j][Q4[i][0]]),Q4[i][2]);
            if(Q4[i][2] == (allcombi[j][Q4[i][1]]-allcombi[j][Q4[i][0]])){
                tmp += Q4[i][3];
                //printf("(j,Q)=(%d,%d)  --  (%d) =? (%d)\n",j,i,(allcombi[j][Q4[i][1]]-allcombi[j][Q4[i][0]]),Q4[i][2]);
            }
        }
        
        //printf("%d\n",tmp);
        if(tmp > ans){
            ans = tmp;
        }
    }
    
    printf("%d\n",ans);
}