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.*;
import java.math.*;
import java.text.*;

public class Main {
    static PrintWriter out;
    static Reader in;
    public static void main(String[] args) throws IOException {
        input_output();
        //out = new PrintWriter(System.out);
        //in = new Reader(new FileInputStream("card.in"));
        Main solver = new Main();
        solver.solve();
        out.close(); 
        out.flush(); 
    }

    static int INF = (int)1e9+2;
    static int maxn = (int)1e6+5;
    static int mod = (int)1e9+7;
    static int n, m, q, t, k;
    static double pi = 3.141592653589;

    void solve() throws IOException{
        n = in.nextInt();
        k = in.nextInt();
        m = in.nextInt();

        int[] l = new int[m],
              r = new int[m],
              c = new int[m],
              p = new int[m];
        List<Integer> start[] = new ArrayList[n+1],
                      end[] = new ArrayList[n+1];
        for (int i = 1; i <= n; i++) {
            start[i] = new ArrayList<Integer>();
            end[i] = new ArrayList<Integer>();
        }
        for (int i = 0; i < m; i++) {
            l[i] = in.nextInt();
            r[i] = in.nextInt();
            c[i] = in.nextInt();
            p[i] = in.nextInt();

            start[l[i]].add(i);
            end[r[i]].add(i);
        }

        FenwickTree cnt = new FenwickTree(maxn);
        FenwickTree sum = new FenwickTree(maxn);

        long ans = 0;
        for (int i = 1; i <= n; i++) {
            for (int id: start[i]) {
                cnt.update(p[id], c[id]);
                sum.update(p[id], (long)c[id]*p[id]);
            }

            int idx = bs(cnt);
            long count = cnt.query(idx),
                 val = sum.query(idx);
            if (count <= k) ans += val;
            else ans += val-(count-k)*idx;

            for (int id: end[i]) {
                cnt.update(p[id], -c[id]);
                sum.update(p[id], -(long)c[id]*p[id]);
            }
        }

        out.println(ans);
    }

    //<>

    static int bs(FenwickTree cnt) {
        int lo = 1, hi = maxn-1, mid, res = maxn-1;
        while (lo <= hi) {
            mid = (lo+hi)/2;
            if (check(mid, cnt)) {
                hi = mid-1;
                res = mid;
            } else {
                lo = mid+1;
            }
        }
        return res;
    }

    static boolean check(int mid, FenwickTree cnt) {
        if (cnt.query(mid) >= k) return true;
        return false;
    }

    static class FenwickTree {
        long[] bit;

        FenwickTree(int n) { bit = new long[n + 1]; }

        long query(int l, int r) {
            if(l > r)
                return 0;
            return query(r) - query(l - 1);
        }

        long query(int idx) {
            long s = 0;
            while(idx > 0) {
                s += bit[idx];
                idx ^= idx & -idx;
            }
            return s;
        }

        void update(int idx, long val) {
            while(idx < bit.length) {
                bit[idx] += val;
                idx += idx & -idx;
            }
        }
    }

    static class Reader {
 
        private InputStream mIs;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
    
        public Reader() {
            this(System.in);
        }
    
        public Reader(InputStream is) {
            mIs = is;
        }
    
        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
    
        }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = mIs.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }
    
        public String nextLine() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndOfLine(c));
            return res.toString();
        }
    
        public String next() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }
    
        double nextDouble()
        {
            return Double.parseDouble(next());
        }
    
        public long nextLong() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
    
        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }
    
        public boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }
    
        public boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }
 
    }
    static void input_output() throws IOException {
        File f = new File("in.txt");
        if(f.exists() && !f.isDirectory()) { 
            in = new Reader(new FileInputStream("in.txt"));
        } else in = new Reader();
        f = new File("out.txt");
        if(f.exists() && !f.isDirectory()) {
            out = new PrintWriter(new File("out.txt"));
        } else out = new PrintWriter(System.out);
    }
}