#include <stdio.h>
#include <algorithm>
#include <assert.h>
#include <cmath>
#include <deque>
#include <iostream>
#include <limits.h>
#include<functional>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <stack>
#include <deque>

#define LL long long
#define pii pair<int,int>
#define pLL pair<LL,LL>
#define mp make_pair
#define mt make_tuple
#define pq priority_queue<LL>
#define pqg priority_queue<int,vector<int>,greater<int>>
#define pb push_back
#define vec vector<int>
#define vecll vector<LL>
#define vecpii vector<pii>
#define vecpLL vector<pLL>
#define vecbL vector<bool>
#define endl "\n"
#define REP(e,v) for(auto e:v)
#define rep(i, a, n) for(LL i = a; i < n;i++)
#define arep(i, a, n) for(i = a; i < n;i++)

using namespace std;


struct edge {
    LL to;
    LL cost;
};

/*
 LL V;

 cin >> V;

 vector<edge> G[V];

 rep(i,0,V){
 	 LL e;

 	 cin >> e;

 	 rep(j,0,e){
 	 	 LL to,cost;
 	 	 cin >> to >> cost;

 	 	 G[j].insert(new edge(to,cost));
 	 }
 }

 */

void dijkstra(LL s,LL V,vector<edge> G[],LL d[]) {
    priority_queue<pLL, vector<pLL>, less<pLL> > que;
    fill(d, d+V, INT_MAX);
    d[s] = 0;
    que.push(pLL(0, s));

    while (!que.empty()) {
        pLL p = que.top();
        que.pop();
        int v = p.second;
        if (d[v] < p.first) continue;

        for (int i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(pLL(d[e.to], e.to));
            }
        }
    }
}


int inp(){
	int x;
	scanf("%d",&x);
	return x;
}
LL linp(){
	LL x;
	scanf("%lld",&x);
	return x;
}

void outp(int i){
	printf("%d",i);
}

void loutp(LL i){
	printf("%lld",i);
}

LL mod(LL i){
	return i % 1000000007;
}


LL gcd(LL i,LL j){
	if(j != 0)
		return gcd(j, i % j);
	else
		return i;

}

LL A(){
	LL K,A,B;

	cin >> K >> A >> B;

	rep(i,A,B+1){
		if(i % K == 0) {
			printf("OK");
			return 0;
		}
	}

	printf("NG");

	return 0;
}

LL B(){

	LL X;

	cin >> X;

	LL count = 0;
	LL money = 100;

	while(money < X){
		money *= 1.01;
		count++;

	}

	outp(count);

	return 0;
}

LL C(){
	LL N,M,Q;

	cin >> N >> M >> Q;

	LL four[Q][4];

	rep(i,0,Q){
		rep(j,0,4){
			cin >> four[i][j];
		}

	}

	LL A[10] = {0};
	LL ma = 0;
	arep(A[0],1,M+1){
		arep(A[1],A[0],M+1){
			arep(A[2],A[1],M+1){
				arep(A[3],A[2],M+1){
					arep(A[4],A[3],M+1){
						arep(A[5],A[4],M+1){
							arep(A[6],A[5],M+1){
								arep(A[7],A[6],M+1){
									arep(A[8],A[7],M+1){
										arep(A[9],A[8],M+1){

											LL sum = 0;

											rep(i,0,Q){

												if(four[i][1] <= N
														&& four[i][0]  <= N
														&& A[four[i][1]-1] - A[four[i][0]-1] == four[i][2]){
													sum += four[i][3];
												}
											}

											ma = max(ma,sum);
										}
									}
								}
							}
						}
					}
				}
			}
		}
	}

	cout << ma;

	return 0;
}

LL D(){
	LL A,B,N;

	cin >> A >> B >>N;

	LL ma = 0;
	/*rep(x,0,N+1){
		ma = max(ma,(A*x)/B - A*(x/B));
	}
	*/

	if(B - 1 <= N){
		ma = (A*(B-1))/B - A*((B-1)/B);
	}else{
		ma = (A*N)/B - A*(N/B);
	}


	loutp(ma);

	return 0;
}


signed main() {
	//A();
	//B();
	C();
	//D();
	return 0;
}


Measured memory_bytes: 3608