output_description: Print the maximum possible score of A.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      N M Q
      a_1 b_1 c_1 d_1
      :
      a_Q b_Q c_Q d_Q
attempt: def examA():
      K = I()
      A, B = LI()
      for i in range(A, B + 1):
          if i % K == 0:
              print("OK")
              return
      print("NG")
      return
  
  
  def examB():
      X = I()
      now = 100
      ans = 0
      while now < X:
          ans += 1
          now += now // 100
      print(ans)
      return
  
  
  def examC():
      N, M, Q = LI()
      A = [LI() for _ in range(Q)]
      A.sort()
      dp = [[0] * M for _ in range(N)]
      for i in range(Q):
          a, b, c, d = A[i]
          a -= 1
          b -= 1
          for j in range(M):
              dp[b][j] = max(dp[b][j], 0)
  
      ans = 0
      print(ans)
      return
  
  
  # 反省して下さい。
  def examC2():
      N, M, Q = LI()
      A = [LI() for _ in range(Q)]
      C = list(itertools.combinations_with_replacement(range(1, M + 1), N))
      # rint(C)
      ans = 0
      for L in C:
          cur = 0
          for a, b, c, d in A:
              if L[b - 1] - L[a - 1] == c:
                  cur += d
          ans = max(cur, ans)
      print(ans)
      return
  
  
  def examD():
      A, B, N = LI()
      if N >= B - 1:
          ans = (A * (B - 1)) // B
      else:
          ans = (A * N) // B
      print(ans)
      return
  
  
  def examE():
      N, M = LI()
      ans = []
      if N % 2 == 1:
          for i in range(N // 2):
              ans.append((i + 1, N - i))
      else:
          flag = False
          for i in range(N // 2):
              if N - i - (i + 1) <= N // 2:
                  flag = True
              if flag:
                  ans.append((i + 1, N - i - 1))
              else:
                  ans.append((i + 1, N - i))
      # print(ans)
      for v in ans[:M]:
          print(" ".join(map(str, v)))
      return
  
  
  def examF():
      N = I()
      A = LI()
      V = [[] for _ in range(N)]
      for _ in range(N - 1):
          u, v = LI()
          u -= 1
          v -= 1
          V[u].append(v)
          V[v].append(u)
      dp = [-1] * N
      dp[0] = 1
      LIS = deque()
      LIS.append(A[0])
  
      def dfs(s):
          # print(LIS)
          for i in V[s]:
              if dp[i] != -1:
                  continue
              flag = []
              if A[i] > LIS[-1]:
                  LIS.append(A[i])
                  flag = False
              else:
                  flag = [
                      bisect.bisect_left(LIS, A[i]),
                      LIS[bisect.bisect_left(LIS, A[i])],
                  ]
                  LIS[flag[0]] = A[i]
              dp[i] = len(LIS)
              dfs(i)
              # print(flag)
              if not flag:
                  LIS.pop()
              else:
                  LIS[flag[0]] = flag[1]
          return
  
      dfs(0)
      ans = dp
      for v in ans:
          print(v)
      return
  
  
  import sys, bisect, itertools, heapq, math, random
  from copy import deepcopy
  from heapq import heappop, heappush, heapify
  from collections import Counter, defaultdict, deque
  
  read = sys.stdin.buffer.read
  readline = sys.stdin.buffer.readline
  readlines = sys.stdin.buffer.readlines
  
  
  def I():
      return int(readline())
  
  
  def LI():
      return list(map(int, sys.stdin.readline().split()))
  
  
  def LSI():
      return list(map(str, sys.stdin.readline().split()))
  
  
  def LS():
      return sys.stdin.readline().split()
  
  
  def SI():
      return sys.stdin.readline().strip()
  
  
  global mod, mod2, inf, alphabet, _ep
  mod = 10**9 + 7
  mod2 = 998244353
  inf = 10**18
  _ep = 10 ** (-12)
  alphabet = [chr(ord("a") + i) for i in range(26)]
  
  sys.setrecursionlimit(10**7)
  
  if __name__ == "__main__":
      examC2()
  
  """
  142
  12 9 1445 0 1
  asd dfg hj o o
  aidn
  """
  
problem_description: Statement
  
  Given are positive integers N, M, Q, and Q quadruples of integers ( a_i , b_i
  , c_i , d_i ).
  
  Consider a sequence A satisfying the following conditions:
  
    * A is a sequence of N positive integers.
    * 1 \leq A_1 \leq A_2 \le \cdots \leq A_N \leq M.
  
  Let us define a score of this sequence as follows:
  
    * The score is the sum of d_i over all indices i such that A_{b_i} - A_{a_i} = c_i. (If there is no such i, the score is 0.)
  
  Find the maximum possible score of A.
samples: [{"input": "3 4 3\n    1 3 3 100\n    1 2 2 10\n    2 3 2 10", "output": "110\n    \n\nWhen A = \\\\{1, 3, 4\\\\}, its score is 110. Under these conditions, no sequence\nhas a score greater than 110, so the answer is 110.\n\n* * *"}, {"input": "4 6 10\n    2 4 1 86568\n    1 4 0 90629\n    2 3 0 90310\n    3 4 1 29211\n    3 4 3 78537\n    3 4 2 8580\n    1 2 1 96263\n    1 4 2 2156\n    1 2 0 94325\n    1 4 3 94328", "output": "357500\n    \n\n* * *"}, {"input": "10 10 1\n    1 10 9 1", "output": "1"}]