import Data.Array

main = do
  li <- getLine
  let [n,m,q] = map read $ words li
  co <- getContents
  let abcds = map (t4 . map read . words) $ lines co
  let ans = compute n m q abcds
  print ans

t4 [a,b,c,d] = (a,b,c,d)

{-
N,Mが大したことないから列挙する？
-}

compute :: Int -> Int -> Int -> [(Int,Int,Int,Int)] -> Int
compute n m q abcds = maximum (map (value n abcds) $ gen m n 1)

gen m 0 _ = [ [] ]
gen m n a = [ i:is | i <- [a..m-n+1], is <- gen m (pred n) i ]

value n abcds as = sum [ d | (a,b,c,d) <- abcds, arr ! b - arr ! a == c ]
  where
    arr = listArray (1,n) as