fun main() {
    println(solve())
}

val solve: () -> Any = {
    val (N, M, Q) = readIntList()
    val list = List(Q){readIntList()}
    val l = listOf(1)

    fun f(li:List<Int>) :Int{
        if (li.size == N) {
            var res = 0
            for (l in list) {
                if (li[l[1]-1] - li[l[0]-1] == l[2]) res += l[3]
            }
            return res
        }
        var max = 0
        for(it in li.last()..M) {
            val n = f(li + it)
            if (n > max) max = n
        }
        return max
    }
    f(l)
}

val mod: Int = 1_000_000_007

fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

fun <T> T.alsoPrintln() = also { println(this) }

fun Boolean.toYesOrNo(yes: String = "Yes", no: String = "No") = if (this) yes else no