using System;
using System.Collections;
using System.Collections.Generic;
using System.IO.Pipes;
using System.Linq;
using System.Numerics;
using System.Security.Cryptography;
using System.Text;
using System.Threading;

namespace ForATCODER
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int ccc = 0;

            int[] d = s2iarray(Console.ReadLine().Split(' '));
            int[] A = new int[d[2]];
            int[] B = new int[d[2]];
            int[] C = new int[d[2]];
            int[] D = new int[d[2]];
            int[] a = new int[d[0]];
            ulong scorem = 0;
            for (int j = 0; j < a.Length; j++)

            {
                a[j] = 1;

            }
         a[a.Length-1] = a[a.Length - 1]-1;
                for (int i = 0; i < d[2]; i++)
            {
                int[] tmp = s2iarray(Console.ReadLine().Split(' '));
                A[i] = tmp[0];
                B[i] = tmp[1];
                C[i] = tmp[2];
                D[i] = tmp[3];
            }
            bool calc = false;
            while (true)
            {
                if (calc && a[0] == d[1]) break;
                int p_ = a.Length-1;
               for(int i = a.Length-1;i >=1;i--)
                {
                    if (a[i] - a[i - 1] >= 1) p_ = i-1;
                }
                //reset
                for (int i = 0; i <p_; i++)
                {
                    a[i] = 1;
                }
                a[p_]++;
#if DEBUG
                   Console.WriteLine("[{0}]", string.Join(", ", a));
                if (!checka(a, d[1]))
                {
                    RESULT("error");
                    return;
                }
                ccc++;
#endif
                //得点
                ulong score = 0;
                for (int i = 0; i < d[2]; i++)
                {
                    int c = a[B[i] -1] - a[A[i] - 1]; //a_Bi - a_Ai
                    int c_ = C[i];//Ci
                    if (c == c_)
                    {
                        score += (ulong)D[i];
                     //  RESULT(score);
                    }
                }
                if (scorem < score) scorem = score;
                calc = true;
            }
          
            RESULT(scorem);
       //     RESULT(ccc);

        }
     public static bool checka(int[] a,int m)
        {
            int back = 1;
            for(int i = 0; i<a.Length;i++)
            {
                if(a[i] >=1 && a[i] <=m)
                {
if(a[i] >= back)
                    {
                        back = a[i];
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }
            }
            return true;
        }
        public static ulong pow(int a, int b)
        {
            ulong res = 1;
            for (int i = 0; i < b; i++)
            {
                res *= (ulong)a;
            }
            return res;
        }
        static int s2i(String s)
        {
            return Convert.ToInt32(s);
        }
        static ulong s2l(String s)
        {
            return Convert.ToUInt64(s);
        }
        static void RESULT(double res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(long res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(ulong res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(int res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(String res)
        {
            Console.WriteLine(res);
        }
        static String[] ReadLineAll(int count)
        {
            String[] res = new String[count];
            for (int i = 0; i < count; i++)
            {
                res[i] = Console.ReadLine();
            }
            return res;
        }

        static int[] s2iarray(String[] src)
        {
            int len = src.Length;
            int[] res = new int[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt32(src[i]);
            }
            return res;
        }
        static long[] s2larray(String[] src)
        {
            int len = src.Length;
            long[] res = new long[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt64(src[i]);
            }
            return res;
        }
        static ulong[] s2larray2(String[] src)
        {
            int len = src.Length;
            ulong[] res = new ulong[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToUInt64(src[i]);
            }
            return res;
        }
    }
}


Measured memory_bytes: 27572