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: #!/usr/bin/env python
  import os
  import sys
  from io import BytesIO, IOBase
  
  
  def main():
      n, m, q = map(int, input().split())
      # print(n,m,q)
      a = [[int(x) for x in input().split()] for _ in range(q)]
      # print(a)
      ans = 0
  
      import itertools
  
      for b in itertools.combinations_with_replacement([i for i in range(1, m + 1)], n):
          cnt = 0
          for v in a:
              if b[v[1] - 1] - b[v[0] - 1] == v[2]:
                  cnt += v[3]
          ans = max(ans, cnt)
  
      print(ans)
  
  
  # region fastio
  
  BUFSIZE = 8192
  
  
  class FastIO(IOBase):
      newlines = 0
  
      def __init__(self, file):
          self._fd = file.fileno()
          self.buffer = BytesIO()
          self.writable = "x" in file.mode or "r" not in file.mode
          self.write = self.buffer.write if self.writable else None
  
      def read(self):
          while True:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              if not b:
                  break
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines = 0
          return self.buffer.read()
  
      def readline(self):
          while self.newlines == 0:
              b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
              self.newlines = b.count(b"\n") + (not b)
              ptr = self.buffer.tell()
              self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
          self.newlines -= 1
          return self.buffer.readline()
  
      def flush(self):
          if self.writable:
              os.write(self._fd, self.buffer.getvalue())
              self.buffer.truncate(0), self.buffer.seek(0)
  
  
  class IOWrapper(IOBase):
      def __init__(self, file):
          self.buffer = FastIO(file)
          self.flush = self.buffer.flush
          self.writable = self.buffer.writable
          self.write = lambda s: self.buffer.write(s.encode("ascii"))
          self.read = lambda: self.buffer.read().decode("ascii")
          self.readline = lambda: self.buffer.readline().decode("ascii")
  
  
  sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
  input = lambda: sys.stdin.readline().rstrip("\r\n")
  # endregion
  
  if __name__ == "__main__":
      main()
  
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"}]