import scala.io.StdIn

object Main extends App {
  val Array(n, m, q) = StdIn.readLine().split(" ").map(_.toInt)
  val a = (0 until q).map { _ =>
    val Array(a, b, c, d) = StdIn.readLine().split(" ").map(_.toInt)
    Item(a - 1, b - 1, c, d)
  }

  var best = 0
  def f(x: Int, n: Int, list: Vector[Int]): Unit = {
    if (x <= m) {
      if (n == 0) {
        val res = a.foldLeft(0) { case (acc, Item(a, b, c, d)) =>
          if (list(b) - list(a) == c) acc + d else acc
        }
        best = best max res
      } else {
        for (i <- x to m)
          f(i, n - 1, list :+ i)
      }
    }
  }
  f(1, n, Vector.empty)
  println(best)

  case class Item(a: Int, b: Int, c: Int, d: Int)

  def readIntPair: (Int, Int) = {
    val Array(x, y) = StdIn.readLine().split(" ").map(_.toInt)
    (x, y)
  }
}