#include <bits/stdc++.h>

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void pout(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void pout(const T &value, const Args&... args){std::cout << value << " ";pout(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;


namespace sort_all{
  template <typename T>
  void sort_with_ord(const std::vector<int> &ord, int N, std::vector<T> &a){
    std::vector<T> temp(N);
    for(int i = 0; i < N; ++i) temp[i] = a[ord[i]];
    std::swap(temp, a);
  }

  template <typename T, typename ...Args>
  void sort_with_ord(const std::vector<int> &ord, int N, std::vector<T> &a, Args&... args){
    std::vector<T> temp(N);
    for(int i = 0; i < N; ++i) temp[i] = a[ord[i]];
    std::swap(temp, a);
    sort_with_ord(ord, N, args...);
  }

  template <typename Compare, typename ...Args>
  void run(const Compare &compare, int N, Args&... args){
    std::vector<int> ord(N);
    std::iota(ord.begin(), ord.end(), 0);
    std::sort(ord.begin(), ord.end(), compare);

    sort_with_ord(ord, N, args...);
  }
};


//int dp[100][20][20];

//int dp[100][100];


template <typename F>
struct FixPoint : F{
  explicit constexpr FixPoint(F &&f) noexcept : F(std::forward<F>(f)){}

  template <typename... Args>
  constexpr decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, std::forward<Args>(args)...);
  }
};

template <typename F>
static inline constexpr decltype(auto) make_fix_point(F &&f){
  return FixPoint<F>(std::forward<F>(f));
}



int main(){
  int N, M, Q;

  while(cin >> N >> M >> Q){
    vector<int> a(Q), b(Q), c(Q), d(Q);
    REP(i,Q){
      cin >> a[i] >> b[i] >> c[i] >> d[i];
      --a[i], --b[i];
    }

    //    i64 cnt = 0;

    vector<int> memo(N);

    auto f =
      make_fix_point([&](auto &&f, int i, int j) -> int{
                       if(i == N){
                         //++cnt;

                         //dump(memo);

                         int t = 0;


                         REP(k,Q){
                           if(memo[b[k]] - memo[a[k]] == c[k]) t += d[k];
                         }

                         return t;
                       }

                       int ret = 0;
                       
                       FORE(k,j,M){
                         memo[i] = j;
                         chmax(ret, f(i+1, k));
                       }

                       return ret;
                     });

    int ans = f(0, 1);
    //    dump(cnt);

    //    int ans = 0;

    /*

    sort_all::run([&](int i, int j){return a[i] < a[j];}, Q, a, b, c, d);
    
    int ans = 0;

    fill_array(dp, 0);
    
    REP(i,N){
      FORE(j,1,M){
        chmax(dp[i][j], dp[i-1][j]);
      }
      
      FORE(j,1,M){

        

        REP(k,Q){
          if(a[k] == i){
            chmax(dp[b[i]][j+c[i]], dp[i][j] + d[i]);
          }
        }

      }

      FORE(j,1,M){
        chmax(dp[i][j], dp[i][j-1]);
      }
    };

    
    REP(i,N){
      FORE(j,1,M){
        cerr << dp[i][j] << " ";
      }
      cerr << endl;
    }
    

    REPE(j,N){
      REPE(k,M){
        chmax(ans, dp[j][k]);
      }
      }*/
    

    pout(ans);
  }


  return 0;
}


Measured memory_bytes: 3624