using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush=
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		struct Query {
			public int a;
			public int b;
			public int c;
			public int d;
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadInt;
			var M = cin.ReadInt;
			var Q = cin.ReadInt;
			var board = new Query[Q];
			Dictionary<(int a, int c), int>[] D = new Dictionary<(int a, int c), int>[N];
			for(int i = 0; i<N; i++) {
				D[i]=new Dictionary<(int a, int c), int>();
			}
			for(int i = 0; i<Q; i++) {
				var l = cin.ReadIntArray(4);
				D[l[1]-1].Add((l[0]-1, l[2]), l[3]);
			}
			int res = 0;
			var A = new int[N];
			A[0]=1;
			search(ref res, A, 1, 0, D, N, M);
			Console.WriteLine(res);
		}
		private void search(ref int max, int[] A, int index, int tmp,
		Dictionary<(int a, int c), int>[] D, int N,int M) {
			if(index==N) {
				if(tmp>max) max=tmp;
				return;
			} else {
				for(int i = A[index-1]; i<=M; i++) {
					A[index]=i;
					var newC = 0;
					for(int a = 0; a<index; a++) {
						if(D[index].ContainsKey((a, A[index]-A[a])))
							newC+=D[index][(a, A[index]-A[a])];
					}
					search(ref max, A, index+1, tmp+newC, D, N, M);
				}
			}
		}
	}
	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
		
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator=separator;
			this._stream=stream;
			inputStream=new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count!=0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i<tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i<N; ++i)
				ret[i]=Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i<N; ++i) ret[i]=ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i<N; ++i) ret[i]=ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i<N; ++i) ret[i]=ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek()==-1; }
		}
	}

}

Measured memory_bytes: 28020