#include<bits/stdc++.h>
#define int unsigned long long
#define float double
#define endl "\n"
#define debug cout<<"Good uptill here"<<endl<<flush;
#define deb(x) cout<<#x<<":"<<x<<endl<<flush;

using namespace std;
const int N = 11;
int n,m,q;

int pts[N][N][N];
int dp[N][N];
bool visit[N][N] = {0};

int solve(int x,int y,vector<int> value){
	if(x>=n) return 0;
	if(visit[x][y]) return dp[x][y];
	visit[x][y] = true;
	int ans = 0;
	for(int i=0;i<value.size();i++){
		ans += pts[x][i][y-value[i]];
	}
	value.push_back(y);
	int res = 0;
	for(int i=y;i<=m;i++){
		res = max(res,solve(x+1,i,value));
	}
	dp[x][y] = ans + res;
	return dp[x][y];
}
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	//CODE FOR SPECIFIED INPUT AND OUTPUT
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	cin>>n>>m>>q;
	memset(pts,0,sizeof(pts));
	memset(visit,0,sizeof(visit));
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<q;i++){
		int a,b,c;
		cin>>a>>b>>c;
		a--; b--;
		cin>>pts[b][a][c];
	}
	int ans = 0;
	for(int i=1;i<=m;i++){
		vector<int> temp;
		ans = max(ans,solve(0,i,temp));
	}
	cout<<ans<<endl;
	return 0;
}

