local mmi, mma = math.min, math.max
local mfl, mce = math.floor, math.ceil
local n, m, q = io.read("*n", "*n", "*n")
local t = {}
for iq = 1, q do
  local a, b, c, d = io.read("*n", "*n", "*n", "*n")
  t[iq] = {a, b, c, d}
end

local function combination_get_map(n)
  local combmap = {}
  for i = 1, n do
    combmap[i] = {}
    local ret = 1
    for j = 1, i do
      ret = mfl(ret * (i + 1 - j) / j)
      combmap[i][j] = ret
    end
  end
  return combmap
end
local function combination_get_count(combmap, n, k)
  if k < 0 then return 0
  elseif n < k then return 0
  elseif k == 0 then return 1
  else return combmap[n][k]
  end
end

local function combination_get_array(combmap, n, k, idx)
  local rem = k
  local retary = {}
  for i = 1, n do
    local useCnt = combination_get_count(combmap, n - i, rem - 1)
    local unuseCnt = combination_get_count(combmap, n - i, rem)
    if idx <= useCnt then
      rem = rem - 1
      table.insert(retary, i)
    else
      idx = idx - useCnt
    end
  end
  return retary
end

local combmap = combination_get_map(n + m - 1)
local combcnt = combination_get_count(combmap, n + m - 1, n)
local ans = 0
for i = 1, combcnt do
  local ary = combination_get_array(combmap, n + m - 1, n, i)
  for j = 1, n do
    ary[j] = ary[j] - j + 1
  end
  local r = 0
  for iq = 1, q do
    local a, b, c, d = unpack(t[iq])
    if ary[b] - ary[a] == c then
      r = r + d
    end
  end
  ans = mma(ans, r)
end
print(ans)
