import java.io.PrintWriter
import kotlin.math.max

fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = nextList().map(String::toInt)
fun nextLongList() = nextList().map(String::toLong)
fun nextDoubleList() = nextList().map(String::toDouble)

val pw = PrintWriter(System.out)
fun print(s: Any = "") = pw.print(s)
fun println(s: Any = "") = pw.println(s)

fun <T> Iterable<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)
fun <T> Array<T>.join(separator: CharSequence = ", ", prefix: CharSequence = "", postfix: CharSequence = "") = joinToString(separator, prefix, postfix)

fun main(args: Array<String>) {
    main()
    pw.flush()
}


fun main() {
    val (N, M, Q) = nextIntList()
    val R = Array(Q) { nextIntList() }
    val tmp = arrayOf(1)
    fun dfs(A: Array<Int>): Int {
        if (A.size == N + 1) {
            var score = 0
            for ((a, b, c, d) in R) {
                if (A[b] - A[a] == c) score += d
            }
            return score
        }
        var ans = 0
        val AA = A.clone() + A.last()
        while (AA.last() <= M) {
            ans = max(ans, dfs(AA))
            AA[AA.size - 1]++
        }
        return ans
    }

    val ans = dfs(tmp)
    println(ans)
}