#include <stdio.h>

int main(void)
{
  int g, h, i, j, k, l, m, n, o, p, q, nn, mm, qq;
  int a[50], b[50], c[50], d[50], e[11] = {0}, sum = 0, result = 0;
  
  scanf("%d %d %d", &nn, &mm, &qq);

  
  for( i = 0; i < nn; i++ ){
      scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
  }

  for( g = 1; g <= mm; g++ ){
      for( h = 1; h <= mm; h++ ){
          for( i = h; i <= mm; i++ ){
              for( j = i; j <= mm; j++ ){
                  for( k = j; k <= mm; k++ ){
                      for( l = k; l <= mm; l++ ){
                          for( m = l; m <= mm; m++ ){
                              for( n = m; n <= mm; n++ ){
                                  for( o = n; o <= mm; o++ ){
                                      for( p = o; p <= mm; p++ ){
                                          sum = 0;
                                          e[1] = h-1;
                                          e[2] = h;
                                          e[3] = i;
                                          e[4] = j;
                                          e[5] = k;
                                          e[6] = l;
                                          e[7] = m;
                                          e[8] = n;
                                          e[9] = o;
                                          e[10] = p;
                                          for( q = 0; q < 3; q++ ){
                                            
                                              if( c[q] == (e[b[q]] - e[a[q]]) ){
                                                  sum += d[q];
                                              }
                                            
                                          }
                                          
                                          if( result <= sum ){
                                              result = sum;
                                          }
                                        
                                      }
                                  }
                              }
                          }
                      }
                  }
              }
          }
      }
  }

  printf("%d\n", result);
  return 0;
}