#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); i--)
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<long long>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define couta(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yesno(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
typedef long long lint;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector<vector<int> > VVI;
typedef vector<vector<long long> > VVLL;
typedef vector<vector<bool> > VVB;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
using UnweightedGraph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
const long long INF = 2000000000ll;
const long double PI = acosl(-1);
const long double EPS = 1e-9;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



long long power(long long a, long long b) {return b?power(a*a,b/2)*(b%2?a:1):1;}
long long perm(long long N, long long K){
    long long x=1;
    for(long long i=1;i<=K;i++)
    {
        x=x*(N-i+1);
    }
    return x;
}
long long factorial(long long N) {return perm(N,N);}
long long comb(long long N,long long K) {return factorial(N)/factorial(K)/factorial(N-K);}
long long hcomb(long long N, long long K) {return comb(N+K-1, N-1);}

int dtoi(double d) {return round(d);}

bool isprime(int n) {
    if (n < 2) return false;
    for (int i = 2; i*i <= n; ++i) {
        if (n % i ==  0) return false;
    }
    return true;
}

long long mystoll(string s){
    long long ans = 0;
    for (int i = (int) s.length()-1; i >= 0; i--){
        ans += (s[i]-'0') * power(10,s.length()-1-i);
    }
    return ans;
}

template<class T>
long long SUM(T a) {
    long long sum = 0;
    for(auto itr : a) sum += itr;
    return sum;
}

void solve(int64_t N, int64_t M, int Q, const vector<int64_t> & a, const vector<int64_t> & b, const vector<int64_t> & c, const vector<int64_t> & d);

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int N, M;
    int Q;
    cin >> N >> M >> Q;
    vector<int64_t> a(Q), b(Q), c(Q), d(Q);
    REP (i, Q) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    solve(N, M, Q, a, b, c, d);
    return 0;
}

void solve(int64_t N, int64_t M, int Q, const vector<int64_t> & a, const vector<int64_t> & b, const vector<int64_t> & c, const vector<int64_t> & d) {
    LL ans = 0;
    VI A(N);
    REPP(i0,M) FOR(i1,i0,M+1) FOR(i2,i1,M+1) FOR(i3,i2,M+1) FOR(i4,i3,M+1) FOR(i5,i4,M+1) FOR(i6,i5,M+1) FOR(i7,i6,M+1) FOR(i8,i7,M+1) FOR(i9,i8,M+1) {
        A[0] = i0;
        A[1] = i1;
        A[2] = i2;
        A[3] = i3;
        A[4] = i4;
        A[5] = i5;
        A[6] = i6;
        A[7] = i7;
        A[8] = i8;
        A[9] = i9;
        LL temp = 0;
        REP(i,Q) {
            if (A[b[i]]-A[a[i]] == c[i]) temp += d[i];
        }
        ans = max(ans,temp);
    }
    pa;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_c && sh test.sh
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_c && sh etest.sh
cd ~/Desktop/Programming/AtCoder/contest/abc165/abc165_c && sh submit.sh
*/


Measured memory_bytes: 3652