
import qualified Data.Vector.Unboxed as U
import qualified Data.Vector.Unboxed.Mutable as UM
import qualified Data.Vector as V
import qualified Data.ByteString.Char8 as C
import Debug.Trace
import Data.List
import Control.Monad
import Data.Ord
import Data.Maybe
import qualified Data.Set as S

r :: Int -> IO (U.Vector Int)
r n = U.unfoldrN n (C.readInt . C.dropWhile (==' ')) <$> C.getLine

r' :: IO [Int]
r'  =   unfoldr    (C.readInt . C.dropWhile (==' ')) <$> C.getLine

data Q = Q {a::Int,b::Int,c::Int,points::Int} deriving Show

main :: IO ()
main = do
    [n,m,q] <- r'
    qs <- replicateM q (r'>>=(\[a,b,c,d]->return (Q a b c d) ))
    print $ maximum $ map (pointsOf qs) $ generate n m

generate :: Int -> Int -> [[Int]]
generate 1 m = map (:[]) [1..m]
generate n m =
    concatMap (\(r@(h:t)) ->
            map (:r) [1..h]) (generate (n-1) m :: [[Int]])

pointsOf :: [Q] -> [Int] -> Int
pointsOf qs as =
    sum $ map (pts as) qs


pts as q = if as!!((b q) -1) - as!!((a q) -1) == c q then points q else 0
