Buber is a Berland technology company that specializes in waste of investor's money. Recently Buber decided to transfer its infrastructure to a cloud. The company decided to rent CPU cores in the cloud for n consecutive days, which are numbered from 1 to n. Buber requires k CPU cores each day.

The cloud provider offers m tariff plans, the i-th tariff plan is characterized by the following parameters:

  * l_i and r_i — the i-th tariff plan is available only on days from l_i to r_i, inclusive, 
  * c_i — the number of cores per day available for rent on the i-th tariff plan, 
  * p_i — the price of renting one core per day on the i-th tariff plan. 



Buber can arbitrarily share its computing core needs between the tariff plans. Every day Buber can rent an arbitrary number of cores (from 0 to c_i) on each of the available plans. The number of rented cores on a tariff plan can vary arbitrarily from day to day.

Find the minimum amount of money that Buber will pay for its work for n days from 1 to n. If on a day the total number of cores for all available tariff plans is strictly less than k, then this day Buber will have to work on fewer cores (and it rents all the available cores), otherwise Buber rents exactly k cores this day.

Input

The first line of the input contains three integers n, k and m (1 ≤ n,k ≤ 10^6, 1 ≤ m ≤ 2⋅10^5) — the number of days to analyze, the desired daily number of cores, the number of tariff plans.

The following m lines contain descriptions of tariff plans, one description per line. Each line contains four integers l_i, r_i, c_i, p_i (1 ≤ l_i ≤ r_i ≤ n, 1 ≤ c_i, p_i ≤ 10^6), where l_i and r_i are starting and finishing days of the i-th tariff plan, c_i — number of cores, p_i — price of a single core for daily rent on the i-th tariff plan.

Output

Print a single integer number — the minimal amount of money that Buber will pay.

Examples

Input

5 7 3
1 4 5 3
1 3 5 2
2 5 10 1


Output

44


Input

7 13 5
2 3 10 7
3 5 10 10
1 2 10 6
4 5 10 9
3 4 10 8


Output

462


Input

4 100 3
3 3 2 5
1 1 3 2
2 4 4 4


Output

64
import java.util.*;
import java.io.*;
public class helloworld {
 static long fact[];
 static long max;
 static int ans;
	static class Reader 
    { 
        final private int BUFFER_SIZE = 1 << 16; 
        private DataInputStream din; 
        private byte[] buffer; 
        private int bufferPointer, bytesRead; 
  
        public Reader() 
        { 
            din = new DataInputStream(System.in); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public Reader(String file_name) throws IOException 
        { 
            din = new DataInputStream(new FileInputStream(file_name)); 
            buffer = new byte[BUFFER_SIZE]; 
            bufferPointer = bytesRead = 0; 
        } 
  
        public String readLine() throws IOException 
        { 
            byte[] buf = new byte[64]; // line length 
            int cnt = 0, c; 
            while ((c = read()) != -1) 
            { 
                if (c == '\n') 
                    break; 
                buf[cnt++] = (byte) c; 
            } 
            return new String(buf, 0, cnt); 
        } 
  
        public int nextInt() throws IOException 
        { 
            int ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do
            { 
                ret = ret * 10 + c - '0'; 
            }  while ((c = read()) >= '0' && c <= '9'); 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public long nextLong() throws IOException 
        { 
            long ret = 0; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        public double nextDouble() throws IOException 
        { 
            double ret = 0, div = 1; 
            byte c = read(); 
            while (c <= ' ') 
                c = read(); 
            boolean neg = (c == '-'); 
            if (neg) 
                c = read(); 
  
            do { 
                ret = ret * 10 + c - '0'; 
            } 
            while ((c = read()) >= '0' && c <= '9'); 
  
            if (c == '.') 
            { 
                while ((c = read()) >= '0' && c <= '9') 
                { 
                    ret += (c - '0') / (div *= 10); 
                } 
            } 
  
            if (neg) 
                return -ret; 
            return ret; 
        } 
  
        private void fillBuffer() throws IOException 
        { 
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); 
            if (bytesRead == -1) 
                buffer[0] = -1; 
        } 
  
        private byte read() throws IOException 
        { 
            if (bufferPointer == bytesRead) 
                fillBuffer(); 
            return buffer[bufferPointer++]; 
        } 
  
        public void close() throws IOException 
        { 
            if (din == null) 
                return; 
            din.close(); 
        } 
    } 
	
	static long getSum(int index , long BITree[]) 
    { 
		
        long  sum = 0; // Iniialize result 
      
        // index in BITree[] is 1 more than 
        // the index in arr[] 
    
      
        // Traverse ancestors of BITree[index] 
        while(index>0) 
        { 
            // Add current element of BITree  
            // to sum 
            sum += BITree[index]; 
      
            // Move index to parent node in  
            // getSum View 
            index -= index & (-index); 
        } 
        return sum; 
    } 
  
	static int getMid(int s, int e) 
    { 
        return s + (e - s) / 2; 
    } 
  
    /* 
    * A recursive function to get the sum  
    of values in given range of the array. 
    * The following are parameters for this function. 
    *  
    * st -> Pointer to segment tree 
    * node -> Index of current node in 
    *         the segment tree. 
    * ss & se -> Starting and ending indexes 
    *         of the segment represented 
    *         by current node, i.e., st[node] 
    * l & r -> Starting and ending indexes 
    *         of range query 
    */
    static int MaxUtil(int[] st, int ss, int se,  
                        int l, int r, int node)  
    { 
          
        // If segment of this node is completely 
        // part of given range, then return 
        // the max of segment 
        if (l <= ss && r >= se) 
            return st[node]; 
  
        // If segment of this node does not 
        // belong to given range 
        if (se < l || ss > r) 
            return -1; 
  
        // If segment of this node is partially 
        // the part of given range 
        int mid = getMid(ss, se); 
  
        return Math.max(MaxUtil(st, ss, mid, l, r, 2 * node + 1), 
                    MaxUtil(st, mid + 1, se, l, r, 2 * node + 2)); 
    } 
  
    /* 
    * A recursive function to update the  
    nodes which have the given index in their 
    * range. The following are parameters  
    st, ss and se are same as defined above 
    * index -> index of the element to be updated. 
    */
    static void updateValue(int arr[], int[] st, int ss, 
                    int se, int index, int value, int node) 
    { 
        if (index < ss || index > se) 
        { 
            System.out.println("Invalid Input"); 
            return; 
        } 
  
        if (ss == se) 
        { 
  
            // update value in array and in segment tree 
            arr[index] = value; 
            st[node] = value; 
        }  
        else
        { 
            int mid = getMid(ss, se); 
  
            if (index >= ss && index <= mid) 
                updateValue(arr, st, ss, mid, index, value, 2 * node + 1); 
            else
                updateValue(arr, st, mid + 1, se, index, value, 2 * node + 2); 
  
            st[node] = Math.max(st[2 * node + 1], st[2 * node + 2]); 
        } 
        return; 
    } 
  
    // Return max of elements in range from 
    // index l (query start) to r (query end). 
    static int getMax(int[] st, int n, int l, int r) 
    { 
  
        // Check for erroneous input values 
        if (l < 0 || r > n - 1 || l > r)  
        { 
            System.out.printf("Invalid Input\n"); 
            return -1; 
        } 
  
        return MaxUtil(st, 0, n - 1, l, r, 0); 
    } 
  
    // A recursive function that constructs Segment 
    // Tree for array[ss..se]. si is index of 
    // current node in segment tree st 
    static int constructSTUtil(int arr[], int ss, 
                        int se, int[] st, int si)  
    { 
          
        // If there is one element in array, store 
        // it in current node of segment tree and return 
        if (ss == se)  
        { 
            st[si] = arr[ss]; 
            return arr[ss]; 
        } 
  
        // If there are more than one elements, then 
        // recur for left and right subtrees and 
        // store the max of values in this node 
        int mid = getMid(ss, se); 
  
        st[si] = Math.max(constructSTUtil(arr, ss, mid, st, si * 2 + 1), 
                constructSTUtil(arr, mid + 1, se, st, si * 2 + 2)); 
  
        return st[si]; 
    } 
  
    /* 
    * Function to construct segment tree from 
    given array. This function allocates 
    * memory for segment tree. 
    */
    static int[] constructST(int arr[], int n) 
    { 
  
        // Height of segment tree 
        int x = (int) Math.ceil(Math.log(n) / Math.log(2)); 
  
        // Maximum size of segment tree 
        int max_size = 2 * (int) Math.pow(2, x) - 1; 
  
        // Allocate memory 
        int[] st = new int[max_size]; 
  
        // Fill the allocated memory st 
        constructSTUtil(arr, 0, n - 1, st, 0); 
  
        // Return the constructed segment tree 
        return st; 
    } 
    public static void updateBIT(int n, int index,  
                                        long val , long BITree[] ) 
    { 
        // index in BITree[] is 1 more than  
        // the index in arr[] 
       
        // Traverse all ancestors and add 'val' 
        while(index <= n) 
        { 
        // Add 'val' to current node of BIT Tree 
        BITree[index] += val; 
      
        // Update index to that of parent  
        // in update View 
        index += index & (-index); 
        } 
    } 
    static long mod = 1000000007;
   static long pow(long a , long b , long c)
   {
	   
	   if(b==0)
		   return 1;
	   
	   long ans = pow(a,b/2,c);
	   if(b%2 == 0)
		   return ans*ans%c;
	   
	   return ans*ans%c*a%c;
   }
   
   static long modInverse(long a , long b)
   {
	   return pow(a,b-2,mod);
   }
   
   
   static double d(int x1 , int y1 , int x2 , int y2)
   {
	   double d1 = x1-x2;
	   double d2 = y1-y2;
	   
	   return Math.sqrt(d1*d1-d2*d2);
   }
  

static int low[];
static int p[];
static int parent(int x , int k , int dp[][])
{
	if(k==0)
		return x;
while(k > 0)
{
	if(x == -1)
		break;
	
	int up = low[k];
	k -= p[up];
	x = dp[x][up];
}
return x;
}


static void d(int n , LinkedList<Integer> arr[] , boolean visited[] , int dp[][] , int h[] , int p,int lev)
{
	visited[n] = true;
	int lim = low[visited.length];
	
	dp[n][0] = p;
	int temp = n;
	for(int j = 1 ; j <= lim ; j++)
	{
		if(dp[n][j-1] == -1)
			break;
		
		dp[n][j] = dp[dp[n][j-1]][j-1];
	}
	
	h[n] = lev;
	
	for(Integer i : arr[n])
	{
		if(!visited[i])
		{
			d(i,arr,visited,dp,h,n,lev+1);
		}
	}
}

static int lca(int a , int b , int dp[][] , int h[])
{
	if(h[a] > h[b])
	{
		a = parent(a,h[a]-h[b],dp);
		
	}
	
	else if(h[b] > h[a])
	{
		b = parent(b,h[b]-h[a],dp);
	}
	
	if(a==b)
		return a;
	
	
	int l = 1 , r = h.length;
	
	while(l < r)
	{
		int mid = (l+r)/2;
		if(parent(a,mid,dp) == parent(b,mid,dp))
			r = mid;
		
		else
			l = mid+1;
	}
	
	return parent(a,l,dp);
}


static int check(int s , int f , int t , int dp[][] , int h[])
{
	int sf = lca(s,f,dp,h);
	
	if(lca(sf,t,dp,h) != sf)
	{
		
		
		return h[f]-h[sf]+1;
		
		
	}
	
	if(sf != s && sf != f)
	{
		int ans =  h[lca(s,t,dp,h)]-h[lca(s,f,dp,h)]+h[f]-h[lca(f,t,dp,h)]+1;
		
		
		
		return ans;
	}
	
	else
	{
		int ans = -1;
		
		if(sf == s)
		ans =  h[f]-h[lca(f,t,dp,h)]+1;
		
		else
		ans =   h[lca(s,t,dp,h)] - h[f]+1;
		
		
		
		return ans;
	}
}

static void dfs(int n , LinkedList<Integer> arr[] , boolean visited[] ,int dp[][][][], int zer , int one , int h[])
{
	visited[n] = true;
	ArrayList<Integer> temp = new ArrayList<Integer>();
	
	for(Integer i : arr[n])
	{
		if(!visited[i])
		{
			dfs(i,arr,visited,dp,zer,one,h);
			h[n] += h[i];
			temp.add(i);
		}
	}
	h[n]++;
	int two = visited.length-1-zer-one;
	
	for(int z = 0 ; z <= zer ; z++)
	{
		for(int o = 0 ; o <= one ; o++)
		{
			if(h[n]-z-o <= two && h[n]-z-o >= 0)
			{
				//System.out.println("bro");
			if(z > 0)
			{
				int mn = 1 , mn2 = 1;
				for(Integer i : temp)
				{
				    mn = Math.min(mn, dp[i][z-1][o][1]);
				    mn2 = Math.min(mn2, dp[i][z-1][o][0]);
				}
			
			
			if(mn == 1 || mn2 == 1)
				dp[n][z][o][0] = 1;
			
			}
			
			
			if(o > 0)
			{
				int mn1 = 1 , mn2 = 1 , mn3 = 1;
				for(Integer i : temp)
				{
					mn1 = Math.min(mn1, dp[i][z][o-1][0]);
				    mn2 = Math.min(mn2, dp[i][z][o-1][2]);
				    mn3 = Math.min(mn3, dp[i][z][o-1][1]);
				}
				
				if(mn1 == 1 || mn2 == 1 || mn3 == 1)
					dp[n][z][o][1] = 1;
				
				
			}
			
			
			if(h[n]-z-o > 0)
			{
				int mn1 = 1 , mn2 = 1;
				for(Integer i : temp)
				{
					mn1 = Math.min(mn1, dp[i][z][o][1]);
				   mn2 = Math.min(mn2, dp[i][z][o][2]);
				}
				
				if(mn1 == 1 || mn2 == 1)
					dp[n][z][o][2] = 1;
			}
			
			}
			
		}
	}
}
public static void main(String []args) throws IOException
{
    Reader sc = new Reader();
    int n = sc.nextInt();
    int k = sc.nextInt();
    int m = sc.nextInt();
    
    ArrayList<pair> open[] = new ArrayList[n+1];
	ArrayList<pair> close[] = new ArrayList[n+1];
	
	for(int i = 1; i <= n ; i++)
	{
		open[i] = new ArrayList<pair>();
		close[i] = new ArrayList<pair>();
	}
    for(int i = 1 ; i <= m ; i++)
    {
    	int l = sc.nextInt();
    	int r = sc.nextInt();
    	int c = sc.nextInt();
    	int p = sc.nextInt();
    	
    	
    	open[l].add(new pair(p,c));
    	close[r].add(new pair(p,c));
    }
    
    long cnt[] = new long[1000001];
    long cst[] = new long[1000001];
    
    long ans = 0;
    for(int i = 1 ; i <= n ; i++)
    {
    	for(pair p : open[i])
    	{
    		updateBIT(1000000 , p.p , p.c , cnt);
    		updateBIT(1000000 , p.p , (long)p.p*(long)p.c , cst);
    	}
    	
    	
    	if(getSum(1000000 , cnt) <= k)
    	{
    		ans += getSum(1000000,cst);
    	}
    	
    	else
    	{
    	int l = 1 , r = 1000000;
    	while(l < r)
    	{
    	    int mid = (l+r)/2;
    	    if(getSum(mid,cnt) >= k)
    	    	r = mid;
    	    
    	    else
    	    	l = mid+1;
    	}
    	
    	ans += getSum(l,cst)-(long)(getSum(l,cnt)-k)*(long)l;
    	}
    	
    	for(pair p : close[i])
    	{
    		updateBIT(1000000 , p.p , -p.c , cnt);
    		updateBIT(1000000 , p.p , -(long)p.p*(long)p.c , cst);
    	}
    }
    System.out.println(ans);
}
}

class pair
{
	int p , c;
	public pair(int p , int c)
	{
		this.p = p;
		this.c = c;
	}
}