#include <stdio.h>

int n, m, q, ans, cur, val[15], cnt[15];
int ca[15][55], cc[15][55], cd[15][55];

void dfs(int u) {
    if (u == n + 1) {
        if (cur > ans) ans = cur;
        return;
    }
    for (int i = val[u - 1]; i <= m; i++) {
        val[u] = i;
        int tt = 0;
        for (int j = 1; j <= cnt[u]; j++)
            if (val[u] - val[ca[u][j]] == cc[u][j])
                tt += cd[u][j];
        cur += tt;
        dfs(u + 1);
        cur -= tt;
    }
}

int main() {
    scanf("%d %d %d", &n, &m, &q);
    for (int i = 0; i < q; i++) {
        int a, b, c, d;
        scanf("%d %d %d %d", &a, &b, &c, &d);
        cnt[b]++;
        ca[b][cnt[b]] = a, cc[b][cnt[b]] = c, cd[b][cnt[b]] = d;
    }
    val[0] = 1;
    dfs(1);
    printf("%d\n", ans);
}