using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;

namespace AtCoder
{
    static class Program_D
    {
        class Solver
        {

            int _count = 0;
            int _n;
            int[][] _cond;
            int _maxScore = 0;
            public void Solve()
            {
                var nmq = Ints();
                _n = nmq[0];
                var m = nmq[1];
                var q = nmq[2];
                _cond = new int[q][];
                for (int i = 0; i < q; ++i)
                {
                    _cond[i] = Ints();
                    _cond[i][0]--;
                    _cond[i][1]--;
                }

                var backet = new int[m];

                CreateArray(backet, 0, _n);
                Console.WriteLine(_maxScore);
            }


            private void CreateArray(int[] backet, int idx, int n)
            {
                if(idx==backet.Length-1)
                {
                    backet[idx] = n;
                    Action(backet);
                    return;
                }
                for (int i = n; i >= 0; --i)
                {
                    backet[idx] = i;
                    CreateArray(backet, idx + 1, n - i);
                }
            }

            private void Action(int[] backet)
            {
                // バケツを配列化
                var ary = new int[_n];
                int idx = 0;
                for(int i=0;i<backet.Length;++i)
                {
                    if (backet[i] == 0) continue;
                    for(int j=0;j <backet[i];++j)                        
                    {
                        ary[idx] = i;
                        idx++;
                    }
                }
                // score計算
                int score = 0;
                for(int i=0; i < _cond.Length; ++i)
                {
                    var cond = _cond[i];
                    var c = ary[cond[1]] - ary[cond[0]];
                    if (c == cond[2]) score += cond[3];
                }
                _maxScore = Math.Max(_maxScore, score);
                //Console.WriteLine("backet :"+
                //    string.Join(",", backet.Select(b => b.ToString()).ToArray()));
                //Console.WriteLine("array : "+
                //    string.Join(",", ary.Select(b => b.ToString()).ToArray()));
            }



            // ----------------------------------------------------------------------------

            public int Int()
            {
                return int.Parse(Console.ReadLine());
            }
            public int[] Ints()
            {
                return Console.ReadLine().Split(' ').Select(s => int.Parse(s)).ToArray();
            }
            public long[] Longs()
            {
                return Console.ReadLine().Split(' ').Select(s => long.Parse(s)).ToArray();
            }
            public int[][] MultiInts(int num)
            {
                var result = new int[num][];
                for (int i = 0; i < num; ++i)
                {
                    result[i] = Ints();
                }
                return result;
            }
            public T[] MultiItems<T>(int num, Func<string, T> parser)
            {
                var result = new T[num];
                for (int i = 0; i < num; ++i)
                {
                    result[i] = parser(Console.ReadLine());
                }
                return result;
            }
        }



        static void Main(string[] args)
        {
            new Solver().Solve();
        }
    }
    struct ModInt
    {
        const int MOD = 1000000007;
        long Data;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public ModInt(long data) { if ((Data = data % MOD) < 0) Data += MOD; }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static implicit operator long(ModInt modInt) => modInt.Data;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static implicit operator ModInt(long val) => new ModInt(val);
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator +(ModInt a, ModInt b)
        {
            long res = a.Data + b.Data;
            return new ModInt() { Data = res >= MOD ? res - MOD : res };
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator +(ModInt a, long b) => a.Data + b;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator -(ModInt a, ModInt b)
        {
            long res = a.Data - b.Data;
            return new ModInt() { Data = res < 0 ? res + MOD : res };
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator -(ModInt a, long b) => a.Data - b;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator *(ModInt a, ModInt b) => new ModInt() { Data = a.Data * b.Data % MOD };
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public static ModInt operator /(ModInt a, ModInt b) => a.Data * GetInverse(b);

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public override string ToString() => Data.ToString();

        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        static long GetInverse(long a)
        {
            long div;
            long p = MOD;
            long x1 = 1, y1 = 0, x2 = 0, y2 = 1;
            while (true)
            {
                if (p == 1) return x2;
                div = a / p;
                x1 -= x2 * div;
                y1 -= y2 * div;
                a %= p;
                if (a == 1) return x1;
                div = p / a;
                x2 -= x1 * div;
                y2 -= y1 * div;
                p %= a;
            }
        }
    }

}


Measured memory_bytes: 34072