import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val (n, m, q) = (sc.nextInt(), sc.nextInt(), sc.nextInt())
  val records = (1 to q).map { _ =>
    val (a, b, c, d) = (sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt())
    Record(a, b, c, d)
  }

  val result = new MainIterator(n, m).map { ax =>
    records.map(_.point(ax)).sum
  }.max
  println(result)
}

class MainIterator(n: Int, m: Int) extends Iterator[Array[Int]] {
  private val ax = Array.fill(n)(1)
  private var isNext = true
  override def hasNext: Boolean = isNext

  override def next(): Array[Int] = {
    val result = ax.clone()
    val upPos = if(ax.last != m) {
      Some(ax.length - 1)
    } else {
      ax.indices.reverse.tail.find { pos => ax(pos) < ax(pos + 1) }
    }
    upPos.foreach { pos =>
      ax(pos) += 1
      ((pos + 1) until ax.length).foreach(ax(_) = ax(pos))
    }
    isNext = upPos.isDefined
    result
  }
}

case class Record(a: Int, b: Int, c: Int, d: Int) {
  def point(ax: Array[Int]): Int = {
    if(ax(b - 1) - ax(a - 1) == c) d else 0
  }
}
