let () = Scanf.scanf "%d %d %d\n" @@ fun n m q ->
  let abcds = Array.init q @@ fun _ ->
    Scanf.scanf "%d %d %d %d\n" @@ fun a b c d -> a, b, c, d in
  let ass =
    List.init n (Fun.const ())
    |> Fun.flip List.fold_left [(m, [])] (fun nass () ->
        List.concat @@
        Fun.flip List.map nass @@ fun (n, as_) ->
          List.init n @@ fun a -> (a + 1, a + 1 :: as_))
    |> List.map snd
    |> List.map Array.of_list in
  Printf.printf "%d\n" @@
  List.fold_left (fun m as_ ->
    max m @@
    Array.fold_right (fun (a, b, c, d) -> ( + ) @@
      if as_.(b - 1) - as_.(a - 1) = c then d else 0) abcds 0) min_int ass
  

