using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace ABC165
{
    public class Solve
    {
        public static void Main(string[] args)
        {
            new ABC_C();
        }
    }
    public class ABC_A
    {
        public ABC_A()
        {
            //飛距離をKの倍数にすること
            var k = Ex.ReadInt;
            var l = Ex.ReadIntArray();
            //飛距離の範囲はA以上B以下
            var a = l[0];
            var b = l[1];
            bool ans = false;

            for (int i = a; i <= b; i++)
            {
                if (i % k == 0)
                {
                    ans = true;
                    break;
                }
            }

            var str = ans ? "OK" : "NG";
            str.Cw();
        }
    }
    public class ABC_B
    {
        public ABC_B()
        {
            var x = Ex.ReadLong;
            long ans = 0;
            long i = 100;


            while (i < x)
            {
                i += (long)Math.Floor(i * .01);
                ans++;
            }



            ans.Cw();
        }
    }
    public class ABC_C
    {
        //A は、長さ N の正整数列である。
        int n;
        //1 ≤ A 1 ≤ A 2 ≤ ⋯ ≤ A N ≤ M
        int m;
        long q;
        List<long[]> arr = new List<long[]>();
        long[] A = new long[11];

        //A b i − A a i = c i を満たすような i についての、 d i の総和 (そのような i が存在しないときは 0 )
        //A の得点の最大値を求めてください。
        long ans = 0;

        public ABC_C()
        {
            //正整数 N , M , Q と、 4 つの整数の組 ( a i , b i , c i , d i ) Q 組
            var l = Ex.ReadLongArray();
            n = (int)l[0];
            m = (int)l[1];
            q = l[2];


            for (int i = 0; i < q; i++)
            {
                var lf = Ex.ReadLongArray();
                arr.Add(lf);
            }

            A[0] = 1;
            dfs(1);
            ans.Cw();
        }

        void dfs(int index)
        {
            if (index > n)
            {
                long now = 0;
                foreach (var v in arr)
                {
                    var a = v[0] - 1;
                    var b = v[1] - 1;
                    var c = v[2];
                    var d = v[3];

                    if ((A[b] - A[a]) == c) now += d;
                }

                ans = Math.Max(ans, now);

                return;
            }

            var num = A[index - 1];
            A[index] = num;
            dfs(index + 1);

            while (num < m)
            {
                num++;
                A[index] = num;
                dfs(index + 1);
            }
        }
    }
    public class ABC_D
    {
        long a;
        long b;
        long n;
        public ABC_D()
        {
            // N以下の非負整数
            // floor(Ax/B)−A×floor(x/B)
            // floor(t)とは、実数t以下の最大の整数
            var l = Ex.ReadLongArray();
            a = l[0];
            b = l[1];
            n = l[2];

            var num = Math.Max(0, Math.Min(b - 1, n));
            var ans = (long)Math.Floor(num * a / (double)b);
            ans.Cw();
        }
    }
    public class ABC_E
    {
        public ABC_E()
        {
        }
    }
    public class ABC_F
    {
        public ABC_F()
        {
        }
    }
    public static class Ex
    {
        public static void Cw(this object s) { Console.WriteLine(s); }

        public static List<string> FastSort(this List<string> s) { s.Sort(StringComparer.Ordinal); return s.ToList(); }
        public static string yesno(this bool b) { return b ? "yes" : "no"; }
        public static string YesNo(this bool b) { return b ? "Yes" : "No"; }
        public static string YESNO(this bool b) { return b ? "YES" : "NO"; }

        public static string Read { get { return Console.ReadLine().Trim(); } }
        public static int ReadInt { get { return int.Parse(Read); } }
        public static long ReadLong { get { return long.Parse(Read); } }
        public static double ReadDouble { get { return double.Parse(Read); } }
        public static string[] ReadArray() { return Read.Split(' '); }
        public static int[] ReadIntArray() { return Read.Split(' ').Select(int.Parse).ToArray(); }
        public static long[] ReadLongArray() { return Read.Split(' ').Select(long.Parse).ToArray(); }
        public static string[] ReadArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public static int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public static long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 18876