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: N, M, Q = (int(x) for x in input().split())
  ABCD = [0] * Q
  for T in range(0, Q):
      ABCD[T] = [int(x) for x in input().split()]
  
  MaxP = 0
  for A1 in range(0, M + 1):
      for A2 in range(A1, M + 1):
          if N <= 2:
              Point = 0
              A = [A1, A2]
              for TT in range(0, Q):
                  if A[ABCD[TT][1] - 1] - A[ABCD[TT][0] - 1] == ABCD[TT][2]:
                      Point = Point + ABCD[TT][3]
              if Point > MaxP:
                  MaxP = Point
          else:
              for A3 in range(A2, M + 1):
                  if N <= 3:
                      Point = 0
                      A = [A1, A2, A3]
                      for TT in range(0, Q):
                          if A[ABCD[TT][1] - 1] - A[ABCD[TT][0] - 1] == ABCD[TT][2]:
                              Point = Point + ABCD[TT][3]
                      if Point > MaxP:
                          MaxP = Point
                  else:
                      for A4 in range(A3, M + 1):
                          if N <= 4:
                              Point = 0
                              A = [A1, A2, A3, A4]
                              for TT in range(0, Q):
                                  if (
                                      A[ABCD[TT][1] - 1] - A[ABCD[TT][0] - 1]
                                      == ABCD[TT][2]
                                  ):
                                      Point = Point + ABCD[TT][3]
                              if Point > MaxP:
                                  MaxP = Point
                          else:
                              for A5 in range(A4, M + 1):
                                  if N <= 5:
                                      Point = 0
                                      A = [A1, A2, A3, A4, A5]
                                      for TT in range(0, Q):
                                          if (
                                              A[ABCD[TT][1] - 1] - A[ABCD[TT][0] - 1]
                                              == ABCD[TT][2]
                                          ):
                                              Point = Point + ABCD[TT][3]
                                      if Point > MaxP:
                                          MaxP = Point
                                  else:
                                      for A6 in range(A5, M + 1):
                                          if N <= 6:
                                              Point = 0
                                              A = [A1, A2, A3, A4, A5, A6]
                                              for TT in range(0, Q):
                                                  if (
                                                      A[ABCD[TT][1] - 1]
                                                      - A[ABCD[TT][0] - 1]
                                                      == ABCD[TT][2]
                                                  ):
                                                      Point = Point + ABCD[TT][3]
                                              if Point > MaxP:
                                                  MaxP = Point
                                          else:
                                              for A7 in range(A6, M + 1):
                                                  if N <= 7:
                                                      Point = 0
                                                      A = [A1, A2, A3, A4, A5, A6, A7]
                                                      for TT in range(0, Q):
                                                          if (
                                                              A[ABCD[TT][1] - 1]
                                                              - A[ABCD[TT][0] - 1]
                                                              == ABCD[TT][2]
                                                          ):
                                                              Point = Point + ABCD[TT][3]
                                                      if Point > MaxP:
                                                          MaxP = Point
                                                  else:
                                                      for A8 in range(A7, M + 1):
                                                          if N <= 8:
                                                              Point = 0
                                                              A = [
                                                                  A1,
                                                                  A2,
                                                                  A3,
                                                                  A4,
                                                                  A5,
                                                                  A6,
                                                                  A7,
                                                                  A8,
                                                              ]
                                                              for TT in range(0, Q):
                                                                  if (
                                                                      A[ABCD[TT][1] - 1]
                                                                      - A[ABCD[TT][0] - 1]
                                                                      == ABCD[TT][2]
                                                                  ):
                                                                      Point = (
                                                                          Point
                                                                          + ABCD[TT][3]
                                                                      )
                                                              if Point > MaxP:
                                                                  MaxP = Point
                                                          else:
                                                              for A9 in range(A8, M + 1):
                                                                  if N <= 9:
                                                                      Point = 0
                                                                      A = [
                                                                          A1,
                                                                          A2,
                                                                          A3,
                                                                          A4,
                                                                          A5,
                                                                          A6,
                                                                          A7,
                                                                          A8,
                                                                          A9,
                                                                      ]
                                                                      for TT in range(
                                                                          0, Q
                                                                      ):
                                                                          if (
                                                                              A[
                                                                                  ABCD[
                                                                                      TT
                                                                                  ][1]
                                                                                  - 1
                                                                              ]
                                                                              - A[
                                                                                  ABCD[
                                                                                      TT
                                                                                  ][0]
                                                                                  - 1
                                                                              ]
                                                                              == ABCD[TT][
                                                                                  2
                                                                              ]
                                                                          ):
                                                                              Point = (
                                                                                  Point
                                                                                  + ABCD[
                                                                                      TT
                                                                                  ][3]
                                                                              )
                                                                      if Point > MaxP:
                                                                          MaxP = Point
                                                                  else:
                                                                      for A10 in range(
                                                                          A9, M + 1
                                                                      ):
                                                                          Point = 0
                                                                          A = [
                                                                              A1,
                                                                              A2,
                                                                              A3,
                                                                              A4,
                                                                              A5,
                                                                              A6,
                                                                              A7,
                                                                              A8,
                                                                              A9,
                                                                              A10,
                                                                          ]
                                                                          for TT in range(
                                                                              0, Q
                                                                          ):
                                                                              if (
                                                                                  A[
                                                                                      ABCD[
                                                                                          TT
                                                                                      ][
                                                                                          1
                                                                                      ]
                                                                                      - 1
                                                                                  ]
                                                                                  - A[
                                                                                      ABCD[
                                                                                          TT
                                                                                      ][
                                                                                          0
                                                                                      ]
                                                                                      - 1
                                                                                  ]
                                                                                  == ABCD[
                                                                                      TT
                                                                                  ][2]
                                                                              ):
                                                                                  Point = (
                                                                                      Point
                                                                                      + ABCD[
                                                                                          TT
                                                                                      ][
                                                                                          3
                                                                                      ]
                                                                                  )
                                                                          if Point > MaxP:
                                                                              MaxP = Point
  print(MaxP)
  
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"}]