import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  [n, m, q] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  let
    candidates = map VU.fromList $ f n 1 :: [VU.Vector Int]
      where
        f :: Int -> Int -> [[Int]]
        f 0 _ = [[]]
        f l k = do
          i <- [k..m]
          is <- f (pred l) i
          return $ i : is
  abcds <- sequence . replicate q $ unsafeListToTuple . map unsafeTextToInt . T.words <$> T.getLine :: IO [((Int, Int, Int), Int)]
  let
    evaluate :: VU.Vector Int -> Int
    evaluate v = sum . map snd . filter (p . fst) $ abcds
      where
        p :: (Int, Int, Int) -> Bool
        p (x, y, z) = v VU.! pred y - v VU.! pred x == z
  print . maximum . map evaluate $ candidates

unsafeListToTuple :: [Int] -> ((Int, Int, Int), Int)
unsafeListToTuple [w, x, y, z] = ((w, x, y), z)

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
